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)); }
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" } })); }
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" } })); }
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()}."; }
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); }
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); }
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 })); }
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 })); }
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>()); }