我的控制器中有这段代码:
public ActionResult SaveRecommendedUserDetails(RecommendAFriendViewModel model)
{
if (ModelState.IsValid)
{
Entities.RecommendedUser recommendedUser = new Entities.RecommendedUser();
recommendedUser.Email = model.Email;
recommendedUser.Firstname = model.Firstname;
recommendedUser.Surname = model.Surname;
recommendedUser.Users_UserId = model.UserId;
recommendedUser.JobTitle = model.JobTitle;
recommendedUser.Department = model.Department;
ICollection<Entities.Group.Group> group;
foreach (group in model.Groups)
{
//add the goups from my viewmodel to the entity??
}
ZincService.RecommendedUserService.CreateRecommendedUser(recommendedUser);
return RedirectToAction("RecommendedUsers");
}
else
{
return View("Index", model);
}
}
public class RecommendAFriendViewModel
{
public int UserId { get; set; }
[LocalizedRequired]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[LocalizedRequired]
public string Firstname { get; set; }
[LocalizedRequired]
public string Surname { get; set; }
public string Department { get; set; }
public string JobTitle { get; set; }
public DateTime? DateAndTimeProcessed { get; set; }
public DateTime? DateAndTimeRecommended { get; set; }
public IEnumerable<DataModels.Group.GroupDataModel> Groups { get; set; }
public class RecommendedUser
{
public virtual int RecommendedUserId { get; set; }
public virtual string Firstname { get; set; }
public virtual string Surname { get; set; }
public virtual string Email { get; set; }
public virtual string Department { get; set; }
public virtual string JobTitle { get; set; }
public virtual DateTime? DateAndTimeProcessed { get; set; }
public virtual int Users_UserId { get; set; }
public virtual DateTime? DateAndTimeRecommended { get; set; }
public virtual int AssignedUserId { get; set; }
public virtual ICollection<Group.Group> Groups { get; set; }
}
namespace Zinc.Entities.Group
{ 公共类组 { #region 属性
public virtual int GroupId { get; set; }
public virtual string Name { get; set; }
public virtual bool IsArchived { get; set; }
public virtual bool IsSegment { get; set; }
public virtual bool AllowFiltering { get; set; }
public virtual string SmallImageUrl { get; set; }
public virtual string MediumImageUrl { get; set; }
public virtual string LargeImageUrl { get; set; }
private ICollection<RecommendedUser> _groupRecommendedUsers;
public virtual ICollection<RecommendedUser> RecommendedUsers
{
get
{
if (_groupRecommendedUsers == null)
_groupRecommendedUsers = new List<RecommendedUser>();
return _groupRecommendedUsers;
}
set
{
_groupRecommendedUsers = value;
}
}
有人可以帮忙吗?