public ActionResult Create(ContactAddEditModel contactModel) { try { if (ModelState.IsValid) { var _contactEntity = contactModel.ToEntityContact(); _contactEntity.CreatedDate = contactModel.CreatedDate; _contactEntity.Gender = contactModel.AvailableGender.Where(x => x.Value == contactModel.Gender).FirstOrDefault().Text; _contactEntity.Email = contactModel.Email; _contactEntity.FirstName = contactModel.FirstName; _contactEntity.LastName = contactModel.LastName; _contactEntity.MobilePhone = contactModel.MobilePhone; _contactEntity.Address = contactModel.Address; _contactEntity.Active = contactModel.Active; _contactEntity.CustomerId = contactModel.CustomerId; _contactService.Insert(_contactEntity); _contactUnitOfWork.SaveChanges(); } } catch (Exception) { } return(View("Index")); }
public ActionResult Edit(ContactAddEditModel contactModel) { try { var _contact = _contactService.Find(contactModel.ContactId); if (_contact != null) { _contact.ContactId = contactModel.ContactId; _contact.Active = contactModel.Active; _contact.Address = contactModel.Address; _contact.ContactPhone = contactModel.ContactPhone; _contact.Email = contactModel.Email; _contact.FirstName = contactModel.FirstName; _contact.Gender = contactModel.AvailableGender.Where(x => x.Value == contactModel.Gender).FirstOrDefault().Text; _contact.LastName = contactModel.LastName; _contact.CustomerId = contactModel.CustomerId; _contact.IsDefault = contactModel.IsDefault; _contactService.Update(_contact); _contactUnitOfWork.SaveChanges(); } } catch (Exception) { } return(View("index")); //return View(); }
public static crm_Contacts ToEntityContact(this ContactAddEditModel model) { var _contactEntity = new crm_Contacts(); AutoMapper.Mapper.CreateMap <ContactAddEditModel, crm_Contacts>(); AutoMapper.Mapper.Map(model, _contactEntity); return(_contactEntity); }
public static ContactAddEditModel ToModelContact(this crm_Contacts entity) { var _contactModel = new ContactAddEditModel(); AutoMapper.Mapper.CreateMap <crm_Contacts, ContactAddEditModel>(); AutoMapper.Mapper.Map(entity, _contactModel); return(_contactModel); }
// GET: /Tenant/Create public ActionResult Create() { var model = new ContactAddEditModel(); model.CreatedDate = DateTime.Now; //model.AvailableCountries.Add(new SelectListItem() { Text = "Choose country", Value = "0" }); foreach (var c in _customerService.GetAllCustomers()) { model.AvailableCustomer.Add(new SelectListItem() { Text = c.CustomerName, Value = c.CustomerId.ToString() }); } return(View(model)); }