Exemple #1
0
        public async void EditContact(EditContactModel contact)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync(
                "api/Contact/EditContact", contact);

            response.EnsureSuccessStatusCode();
        }
Exemple #2
0
 public void EditContact(EditContactModel contact)
 {
     if (ModelState.IsValid)
     {
         contactService.EditContact(contact);
     }
 }
        public EditContactResponseViewModel EditContact(EditContactRequestViewModel request)
        {
            EditContactModel editContactModel = Mapper
                                                .Map <EditContactRequestViewModel, EditContactModel>(request);
            AddResultBaseModel <int> flag = new AddResultBaseModel <int>()
            {
                IsSuccessed = false,
                Id          = request.ContactId
            };

            using (var transaction = this.Context.Database.BeginTransaction())
            {
                try
                {
                    flag = _editContactServiceBll.Edit(editContactModel);
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }

            return(new EditContactResponseViewModel()
            {
                IsSuccessed = flag.IsSuccessed, ContactId = flag.Id
            });
        }
Exemple #4
0
        public async Task <IHttpActionResult> UpdateContact(EditContactModel model)
        {
            try
            {
                //validate
                if (!ModelState.IsValid)
                {
                    foreach (var key in ModelState.Keys.Where(key => ModelState[key].Errors.Count > 0))
                    {
                        return(BadRequest(ModelState[key].Errors[0].ErrorMessage));
                    }
                }
                var contact = await _contactService.GetByIdAsync(model.Id);

                if (contact == null)
                {
                    return(BadRequest("Contact does not exist"));
                }
                contact.FirstName = model.FirstName;
                contact.LastName  = model.LastName;
                contact.Phone     = model.Phone;

                await _contactService.UpdateAsync(contact);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #5
0
        public void EditContact(EditContactModel model)
        {
            var contact = context.Contacts.FirstOrDefault(x => x.Id == model.ContactId);

            var newEmails = model.EmailAddresses.Where(x => x.EmailId == 0).Select(x => new Email()
            {
                Adreess = x.Address,
            }).ToList();

            var newPhones = model.PhoneNumbers.Where(x => x.PhoneId == 0).Select(x => new Phone()
            {
                Number = x.Number,
            }).ToList();

            contact.FirstName   = model.FisrtName;
            contact.LastName    = model.LastName;
            contact.DateOfBirth = model.DateOfBirth;

            foreach (var phone in newPhones)
            {
                contact.Phones.Add(phone);
            }

            foreach (var email in newEmails)
            {
                contact.Emails.Add(email);
            }

            //TODO add update and delete existing phones and emails

            context.Contacts.Update(contact);
            context.SaveChanges();
        }
        public AddResultBaseModel <int> Edit(EditContactModel model)
        {
            ContactInfoEntity contactInfoEntity = _contactDal.Find <ContactInfoEntity>(model.ContactId);

            if (model.Cname.Contains("/"))
            {
                contactInfoEntity.Ename = model.Cname;
                contactInfoEntity.Cname = string.Empty;
            }
            else
            {
                contactInfoEntity.Cname = model.Cname;
                contactInfoEntity.Ename = string.Empty;
            }

            contactInfoEntity.Mobile         = model.Mobile;
            contactInfoEntity.LastUpdateTime = DateTime.Now;
            contactInfoEntity.UpdateOid      = "sys";
            contactInfoEntity.DelTime        = DateTime.Now;
            contactInfoEntity.Email          = model.Email;
            if (!string.IsNullOrEmpty(model.IsDel))
            {
                contactInfoEntity.IsDel = model.IsDel;
            }

            _contactDal.Update(contactInfoEntity);

            ContactIdentificationInfoEntity contactIdentificationInfoEntity =
                _contactIdentificationDal.Query <ContactIdentificationInfoEntity>(
                    n => n.Contactid == model.ContactId && n.Iid == model.Iid, true).FirstOrDefault();

            if (contactIdentificationInfoEntity != null)
            {
                contactIdentificationInfoEntity.Iid            = model.Iid;
                contactIdentificationInfoEntity.CardNo         = model.CardNo;
                contactIdentificationInfoEntity.LastUpdateTime = DateTime.Now;
                _contactIdentificationDal.Update(contactIdentificationInfoEntity);
            }
            else
            {
                _contactIdentificationDal.Insert <ContactIdentificationInfoEntity>(new ContactIdentificationInfoEntity()
                {
                    Contactid      = model.ContactId,
                    CardNo         = model.CardNo,
                    Iid            = model.Iid,
                    LastUpdateTime = DateTime.Now
                });
            }

            return(new AddResultBaseModel <int>()
            {
                IsSuccessed = true, Id = model.ContactId
            });
        }