コード例 #1
0
ファイル: MemberContact.cs プロジェクト: sartracks/SARTracks
 public void CopyFrom(MemberContact other)
 {
     this.Member = other.Member;
     this.MemberId = (other.Member == null) ? other.MemberId : other.Member.Id;
     this.Type = other.Type;
     this.SubType = other.SubType;
     this.Priority = other.Priority;
     this.Value = other.Value;
 }
コード例 #2
0
        public DataActionResult SubmitContact(MemberContact model)
        {
            if (!Permissions.HasPermission(PermissionType.EditMemberContacts, model.MemberId)) return GetLoginError();
            List<SubmitError> errors = new List<SubmitError>();
            ModelState.Remove("Member");
            ModelState.Remove("Id");

            if (ModelState.IsValid)
            {
                using (var ctx = this.GetRepository())
                {
                    var oldModel = ctx.Members.IncludePaths("ContactInfo.Member").Where(f => f.Id == model.MemberId).SelectMany(f => f.ContactInfo).SingleOrDefault(f => f.Id == model.Id);
                    if (oldModel == null)
                    {
                        ctx.Members.Single(f => f.Id == model.MemberId).ContactInfo.Add(model);
                    }
                    else
                    {
                        oldModel.CopyFrom(model);

                        if (oldModel.Member == null) oldModel.Member = ctx.Members.Single(f => f.Id == oldModel.MemberId);
                    }
                    ctx.SaveChanges();
                }
            }
            else
            {
                ModelStateToSubmitErrors(errors);
            }
            return Data(new SubmitResult<MemberContact> { Errors = errors.ToArray(), Result = model });
        }