public Contact Parse(ContactModel person) { var doan = uow.Doans.GetByName(person.DoanName, GetEnumFromDescription(person.MienName, typeof(MienList))); var contact = new Contact(); contact.Role = (RoleList) person.Role; contact.DoanId = doan.Id; contact.SaintName = person.SaintName; contact.LastName = person.LastName; contact.MiddleName = person.MiddleName; contact.FirstName = person.FirstName; contact.Email = person.Email; contact.Gender = person.Gender; contact.DateOfBirth = person.DateOfBirth; contact.AddressLine = person.Address; contact.City = person.City; contact.State = person.State; contact.Zip = person.Zip; contact.Phone1 = person.Phone; contact.Status = person.Status; contact.Doan = doan; contact.SaMacDanhSaches = new List<SaMacDanhSach>(); contact.LastUpdate = DateTime.Now; contact.SaMacDanhSaches.Add(uow.SaMacDanhSachs.GetById(4)); return contact; }
public ContactModel Create(Contact person) { return new ContactModel() { Id = person.Id, Role = (int)person.Role, SaintName = person.SaintName, LastName = person.LastName, MiddleName = person.MiddleName, FirstName = person.FirstName, Email = person.Email, Gender = person.Gender, DateOfBirth = person.DateOfBirth, Address = person.AddressLine, City = person.City, State = person.State, Zip = person.Zip, Phone = person.Phone1, Status = person.Status, MienName = GetEnumDescription((MienList)Enum.ToObject(typeof(MienList), uow.Doans.GetById(person.DoanId).MienId)), DoanId = person.DoanId, DoanName = uow.Doans.GetById(person.DoanId).Name }; }
// POST api/values public HttpResponseMessage Post(ContactModel person) { try { var doan = uow.Doans.GetByName(person.DoanName, person.MienId); var member = new Contact() { //DoanId = 1, Role = (RoleList)person.Role, DoanId = doan.Id, SaintName = person.SaintName, LastName = person.LastName, MiddleName = person.MiddleName, FirstName = person.FirstName, Email = person.Email, Gender = person.Gender, DateOfBirth = person.DateOfBirth, AddressLine = person.Address, City = person.City, State = person.State, Zip = person.Zip, Phone1 = person.Phone, Status = person.Status, Doan = doan, SaMacDanhSaches = new List<SaMacDanhSach>(), LastUpdate = DateTime.Now, }; member.SaMacDanhSaches.Add(uow.SaMacDanhSachs.GetById(4)); uow.Contacts.Add(member); uow.Commit(); var addedContact = uow.Contacts.GetById(member.Id); person.Id = addedContact.Id; return Request.CreateResponse(HttpStatusCode.Created, person); } catch (Exception ex) { if (ex.InnerException.InnerException.Message.Contains("Violation of UNIQUE KEY")) { return Request.CreateResponse(HttpStatusCode.InternalServerError, "Member already exist or email address has been used"); } else { return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error adding a new member"); } return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error adding a new member"); } }