public Response <ContactPersonModel> Create(ContactPersonCreateModel createModel)
        {
            try
            {
                using (var unitOfWork = new UnitOfWork())
                {
                    var last = unitOfWork.GetRepository <ContactPerson>().GetAll().OrderByDescending(c => c.ContactPersonId).FirstOrDefault();

                    ContactPerson entity = new ContactPerson
                    {
                        ContactPersonId     = 1,
                        Email               = createModel.Email,
                        Note                = createModel.Note,
                        OfficePhoneNumber   = createModel.OfficePhoneNumber,
                        PartnerId           = createModel.PartnerId,
                        PersonalPhoneNumber = createModel.PersonalPhoneNumber,
                        Position            = createModel.Position,
                        Name                = createModel.Name
                    };


                    if (last != null)
                    {
                        entity.ContactPersonId = last.ContactPersonId + 1;
                    }
                    unitOfWork.GetRepository <ContactPerson>().Add(entity);
                    if (unitOfWork.Save() >= 1)
                    {
                        return(GetById(entity.ContactPersonId));
                    }
                    return(new Response <ContactPersonModel>(0, "Lưu thông tin không thành công", null));
                }
            }
            catch (Exception ex)
            {
                return(new Response <ContactPersonModel>(-1, ex.ToString(), null));
            }
        }
예제 #2
0
        public IHttpActionResult Create(ContactPersonCreateModel createModel)
        {
            var result = handler.Create(createModel);

            return(Ok(result));
        }