Пример #1
0
        public IHttpActionResult PostOrganization(OrganizationEditDTO organization)
        {
            try
            {
                if (identityHelper.GetUserTableName(User) == "Employee")
                {
                    if (organization.CountryId == null || organization.CountryId == 0)
                    {
                        return(BadRequest("Empty CountryId"));
                    }

                    Organization org = organization.FromDTO();
                    //now this information is stored in OrganizationOwner (we do not need this anymore)
                    //  organization.EmployeeId = identityHelper.GetUserTableId(User);
                    UnitOfWork unitOfWork = new UnitOfWork(factory);
                    org.Id = org.NewId(unitOfWork);
                    unitOfWork.OrganizationsRepository.Insert(org);

                    unitOfWork.OrganizationOwnersRepository.Insert(
                        new OrganizationOwner()
                    {
                        DateBegin      = DateTime.Now,
                        EmployeeId     = identityHelper.GetUserTableId(User),
                        OrganizationId = org.Id
                    });

                    //constant types
                    List <OrganizationPropertyType> types = unitOfWork.OrganizationPropertyTypesRepository.Get(d => d.Constant == true && d.CountryId == org.CountryId).ToList();
                    foreach (var type in types)
                    {
                        OrganizationProperty property = new OrganizationProperty();
                        property.Id = property.NewId(unitOfWork);
                        property.OrganizationPropertyTypeId = type.Id;
                        property.OrganizationId             = org.Id;
                        unitOfWork.OrganizationPropertiesRepository.Insert(property);
                    }
                    unitOfWork.Save();
                    OrganizationEditDTO dto = unitOfWork.OrganizationsRepository
                                              .Get(d => d.Id == org.Id, includeProperties: "Country,OrganizationLegalForm")
                                              .FirstOrDefault().MapToEdit();

                    return(CreatedAtRoute("GetOrganizationEdit", new { id = dto.Id }, dto));
                }
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(BadRequest());
        }
Пример #2
0
        public IHttpActionResult PostOrganizationProperty(OrganizationPropertyDTO organizationProperty)
        {
            if (organizationProperty == null)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                OrganizationProperty property   = organizationProperty.FromDTO();
                UnitOfWork           unitOfWork = new UnitOfWork(factory);
                int?propertyCountryId           = unitOfWork.OrganizationPropertyTypesRepository
                                                  .Get(d => d.Id == property.OrganizationPropertyTypeId)
                                                  .Select(d => d.CountryId)
                                                  .FirstOrDefault();
                int?organizationCountryId = unitOfWork.OrganizationsRepository
                                            .Get(d => d.Id == property.OrganizationId)
                                            .Select(d => d.CountryId)
                                            .FirstOrDefault();

                if (propertyCountryId != organizationCountryId)
                {
                    return(BadRequest("Country that property belogs to, doesn't match the Organization registration country"));
                }

                property.Id = property.NewId(unitOfWork);
                unitOfWork.OrganizationPropertiesRepository.Insert(property);
                unitOfWork.Save();
                //  logger.Log(LogLevel.Info, "how to pass objects");
                OrganizationPropertyDTO dto = unitOfWork.OrganizationPropertiesRepository
                                              .Get(d => d.Id == property.Id)
                                              .FirstOrDefault()
                                              .ToDTO();
                dto.OrganizationPropertyType = null;
                return(CreatedAtRoute("GetOrganizationProperty", new { id = dto.Id }, dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #3
0
        public IHttpActionResult PostArrayOrganizationProperty(IEnumerable <OrganizationPropertyConstant> properties)
        {
            if (properties == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            List <OrganizationPropertyDTO> propertiesToReturn = new List <OrganizationPropertyDTO>();

            UnitOfWork unitOfWork = new UnitOfWork(factory);

            try
            {
                foreach (var item in properties)
                {
                    OrganizationProperty organizationProperty = new OrganizationProperty()
                    {
                        DateBegin                  = null,
                        DateEnd                    = null,
                        Deleted                    = null,
                        OrganizationId             = item.OrganizationId,
                        OrganizationPropertyTypeId = item.OrganizationPropertyTypeId,
                        Value = item.Value
                    };

                    int?propertyCountryId = unitOfWork.OrganizationPropertyTypesRepository
                                            .Get(d => d.Id == organizationProperty.OrganizationPropertyTypeId)
                                            .Select(d => d.CountryId)
                                            .FirstOrDefault();
                    int?organizationCountryId = unitOfWork.OrganizationsRepository
                                                .Get(d => d.Id == organizationProperty.OrganizationId)
                                                .Select(d => d.CountryId)
                                                .FirstOrDefault();

                    if (propertyCountryId != organizationCountryId)
                    {
                        return(BadRequest("Country that property belogs to, doesn't match the Organization registration country"));
                    }

                    organizationProperty.Id = organizationProperty.NewId(unitOfWork);
                    unitOfWork.OrganizationPropertiesRepository.Insert(organizationProperty);
                    unitOfWork.Save();

                    OrganizationPropertyDTO property = unitOfWork.OrganizationPropertiesRepository
                                                       .Get(d => d.Id == organizationProperty.Id)
                                                       .FirstOrDefault()
                                                       .ToDTO();
                    property.OrganizationPropertyType = null;
                    propertiesToReturn.Add(property);
                }
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            return(Ok(propertiesToReturn));
        }