コード例 #1
0
        public IHttpActionResult PostOrganizationContactPerson(OrganizationContactPersonDTO organizationContactPerson)
        {
            if (organizationContactPerson == null)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                OrganizationContactPerson person = organizationContactPerson.FromDTO();
                UnitOfWork unitOfWork            = new UnitOfWork(factory);
                person.Id = person.NewId(unitOfWork);
                foreach (var item in person.OrganizationContactPersonContact)
                {
                    item.Id = item.NewId(unitOfWork);
                }
                unitOfWork.OrganizationContactPersonsRepository.Insert(person);
                unitOfWork.Save();

                OrganizationContactPersonDTO dto = unitOfWork.OrganizationContactPersonsViewRepository
                                                   .Get(d => d.Id == person.Id).FirstOrDefault().ToDTO();
                if (person == null)
                {
                    return(NotFound());
                }
                dto.OrganizationContactPersonContact = unitOfWork.OrganizationContactPersonContactsRepository
                                                       .Get(d => d.Deleted != true && d.OrganizationContactPersonId == person.Id, includeProperties: "ContactType")
                                                       .Select(d => d.ToDTO());
                return(CreatedAtRoute("GetOrganizationContactPerson", new { id = dto.Id }, dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #2
0
        public IHttpActionResult PutOrganizationContactPerson(int id, OrganizationContactPersonDTO organizationContactPerson)
        {
            if (organizationContactPerson == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != organizationContactPerson.Id)
            {
                return(BadRequest());
            }
            try
            {
                OrganizationContactPerson person = organizationContactPerson.FromDTO();
                UnitOfWork unitOfWork            = new UnitOfWork(factory);
                unitOfWork.OrganizationContactPersonsRepository.Update(person);
                unitOfWork.Save();

                OrganizationContactPersonDTO dto = unitOfWork.OrganizationContactPersonsViewRepository
                                                   .Get(d => d.Id == id).FirstOrDefault().ToDTO();
                if (dto == null)
                {
                    return(NotFound());
                }
                dto.OrganizationContactPersonContact = unitOfWork.OrganizationContactPersonContactsRepository
                                                       .Get(d => d.Deleted != true && d.OrganizationContactPersonId == id, includeProperties: "ContactType")
                                                       .Select(d => d.ToDTO());
                return(Ok(dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }