Ejemplo n.º 1
0
        public async Task <ServiceResponse <int> > CreateAsync(LocationTypeDto locationType, int userId)
        {
            if (locationType == null)
            {
                throw new ArgumentNullException(nameof(locationType));
            }

            var locationTypes = UnitOfWork.Get <LocationType>().GetAll(t => t.Name.Equals(locationType.Name) && t.ID != locationType.ID);

            if (locationTypes.Any())
            {
                return(new ServiceResponse <int>(ServiceResponseStatus.AlreadyExists));
            }

            var entity = locationType.ToEntity();

            entity.UpdateCreatedFields(userId).UpdateModifiedFields(userId);
            entity.Recommendations.UpdateCreatedFields(userId).UpdateModifiedFields(userId);
            entity.Attachments.UpdateCreatedFields(userId).UpdateModifiedFields(userId);

            var added = UnitOfWork.Get <LocationType>().Add(entity);

            await UnitOfWork.SaveAsync();

            return(new SuccessResponse <int>(added.ID));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateLocationType(int id, [FromBody] LocationTypeDto locationTypeUpdate)
        {
            var locationType = await _locationRepo.GetLocationType(id);

            if (locationType == null)
            {
                return(NotFound(new { error = new string[] { "Inventory Type not found" } }));
            }


            if (string.IsNullOrEmpty(locationTypeUpdate.Name))
            {
                ModelState.AddModelError("error", "Location Type name is required");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            locationType.Name = locationTypeUpdate.Name;

            if (await _locationRepo.Save())
            {
                var returnedLocationType = _mapper.Map <LocationTypeDto>(locationType);
                return(Ok(returnedLocationType));
            }

            return(BadRequest(new { error = new string[] { "Inventory Type not found" } }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateLocationType([FromBody] LocationTypeDto locationType)
        {
            if (string.IsNullOrEmpty(locationType.Name))
            {
                ModelState.AddModelError("error", "LocationType Required");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var newLocationType = new LocationType
            {
                Name = locationType.Name
            };

            _locationRepo.Add(newLocationType);

            if (await _locationRepo.Save())
            {
                return(Ok(newLocationType));
            }

            return(BadRequest(new { error = new string[] { "Error creating Location Type" } }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateLocation(int id, [FromBody] LocationTypeDto model)
        {
            var response = await _clientService.PutAsync($"{_settings.Value.OilApiAddress}Location/UpdateLocation/{id}", model);

            var content = await response.Content.ReadAsStringAsync();

            return(new ObjectResult(content));
        }
        public void BizAction(LocationTypeDto inputData)
        {
            var location = _dbAccess.GetLocationType(inputData.Id);

            if (location == null)
            {
                throw new NullReferenceException("Could not find the location. Someone entering illegal ids?");
            }

            var status = location.UpdateLocationType(inputData.Title);

            CombineErrors(status);

            Message = $"person is update: {location.ToString()}.";
        }
Ejemplo n.º 6
0
        public static LocationTypeDto ToDto(this LocationType model)
        {
            var dto = new LocationTypeDto
            {
                ID          = model.ID,
                Name        = model.Name,
                Description = model.Description,
                Locations   = model.Locations?.Select(l => l.ToDto())
            };

            dto.MapDetails(model);
            dto.CanBeDeleted = (model.Locations?.All(a => a.IsDeleted) ?? false) && !model.IsDeleted;

            return(dto);
        }
Ejemplo n.º 7
0
        public static LocationType ToEntity(this LocationTypeDto dto)
        {
            var entity = new LocationType
            {
                ID              = dto.ID,
                Name            = dto.Name,
                Description     = dto.Description,
                Recommendations = dto.Recommendations.Select(r => r.ToEntity()).ToList(),
                Attachments     = dto.Attachments.Select(a => a.ToEntity()).ToList()
            };

            if (!string.IsNullOrEmpty(dto.MainPicture?.FullPath))
            {
                entity.Attachments.Add(dto.MainPicture.ToEntity());
            }

            return(entity);
        }
        public LocationType BizAction(LocationTypeDto inputData)
        {
            if (string.IsNullOrWhiteSpace(inputData.Title))
            {
                AddError("title is Required.");
                return(null);
            }

            var desStatus = LocationType.CreateLocationType(inputData.Title);

            CombineErrors(desStatus);

            if (!HasErrors)
            {
                _dbAccess.Add(desStatus.Result);
            }

            return(HasErrors ? null : desStatus.Result);
        }
Ejemplo n.º 9
0
        public IActionResult UpdateLocation(int id, [FromBody] LocationTypeDto model
                                            , [FromServices] IActionService <IUpdateLocationTypeAction> service)
        {
            model.Id = id;
            service.RunBizAction(model);

            if (!service.Status.HasErrors)
            {
                return(new ObjectResult(new ResultResponseDto <String, int> {
                    Key = HttpStatusCode.OK,
                    Value = "Location updated..",
                    Subject = model.Id
                }));
            }

            var errors = service.Status.CopyErrorsToString(ModelState);

            return(new ObjectResult(new ResultResponseDto <String, int> {
                Key = HttpStatusCode.BadRequest, Value = errors, Subject = model.Id
            }));
        }
Ejemplo n.º 10
0
        public IActionResult CreateLocation([FromBody] LocationTypeDto model
                                            , [FromServices] IActionService <IPlaceLocationTypeAction> service)
        {
            var roadMap = service.RunBizAction <LocationType>(model);

            if (!service.Status.HasErrors)
            {
                return(new ObjectResult(new ResultResponseDto <String, int>
                {
                    Key = HttpStatusCode.OK,
                    Value = "WorkPackage Created...",
                    Subject = roadMap.Id
                }));
            }

            var errors = service.Status.CopyErrorsToString(ModelState);

            service.Status.CopyErrorsToString(ModelState);
            return(new ObjectResult(new ResultResponseDto <String, int> {
                Key = HttpStatusCode.BadRequest, Value = errors
            }));
        }
Ejemplo n.º 11
0
        public async Task <ServiceResponse <LocationTypeDto> > UpdateAsync(LocationTypeDto locationType, int userId)
        {
            if (locationType == null)
            {
                throw new ArgumentNullException(nameof(locationType));
            }

            var existentEntity = await UnitOfWork.Get <LocationType>().GetAsync(t => t.ID == locationType.ID);

            if (existentEntity == null)
            {
                return(new ServiceResponse <LocationTypeDto>(ServiceResponseStatus.NotFound));
            }

            var locationTypes = UnitOfWork.Get <LocationType>().GetAll(t => t.Name.Equals(locationType.Name) && t.ID != locationType.ID);

            if (locationTypes.Any())
            {
                return(new ServiceResponse <LocationTypeDto>(ServiceResponseStatus.AlreadyExists));
            }

            var entity = locationType.ToEntity();

            existentEntity.Attachments     = GetAttachments(existentEntity.ID).ToList();
            existentEntity.Recommendations = GetRecommendations(existentEntity.ID).ToList();

            existentEntity
            .UpdateFields(entity)
            .UpdateAttachments(entity, UnitOfWork, userId)
            .UpdateRecommendations(entity, UnitOfWork, userId)
            .UpdateModifiedFields(userId);

            UnitOfWork.Get <LocationType>().Update(existentEntity);

            await UnitOfWork.SaveAsync();

            return(new SuccessResponse <LocationTypeDto>());
        }