public IHttpActionResult GetOrganizationProperty(int id) { try { UnitOfWork unitOFWork = new UnitOfWork(factory); OrganizationPropertyDTO property = unitOFWork.OrganizationPropertiesRepository .Get(d => d.Id == id, includeProperties: "OrganizationPropertyType,OrganizationPropertyType.OrganizationPropertyTypeAlias") .FirstOrDefault() .ToDTO(); // logger.Log(LogLevel.Info, "how to pass obkects", null, id, property); //logger.Log<int>(LogLevel.Debug, id); return(Ok(property)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IHttpActionResult PutOrganizationProperty(int id, OrganizationPropertyDTO organizationProperty) { if (organizationProperty == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != organizationProperty.Id) { return(BadRequest()); } 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")); } unitOfWork.OrganizationPropertiesRepository.Update(property); unitOfWork.Save(); // logger.Log(LogLevel.Info, "how to pass objects"); OrganizationPropertyDTO dto = unitOfWork.OrganizationPropertiesRepository .Get(d => d.Id == id) .FirstOrDefault() .ToDTO(); dto.OrganizationPropertyType = null; return(Ok(dto)); } catch (NotFoundException nfe) { return(NotFound()); } catch (ConflictException ce) { return(Conflict()); } catch (Exception e) { return(BadRequest(e.Message)); } }
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)); }