public async Task <ActionResult <Machinery> > Post([FromForm] ToolDto model) { var user = await _accountRepository.GetByIdAsync(model.User); string path = Path.Combine("img/customers", model.CustomerId.ToString(), "tool"); string pathFull = _baseUrl.GetBaseUrl(path); var data = new Tool { Brand = model.Brand, CategoryId = model.CategoryId, CustomerId = model.CustomerId, DateOfPurchase = model.DateOfPurchase, Model = model.Modelo, NameTool = model.NameTool, Observations = model.Observations, Serie = model.Serie, State = model.State, TechnicalSpecifications = model.TechnicalSpecifications, User = user, }; if (model.Img != null) { string nameFile = _imgService.SaveFile(model.Img, pathFull, 1280, 720); if (model.PhotoPath != null) { await _imgService.DeleteFile(pathFull, model.PhotoPath); } data.PhotoPath = nameFile; } await _genericRepository.CreateAsync(data); return(new CreatedAtRouteResult("GetTool", new { id = data.Id }, data)); }
public async Task <ActionResult <WeeklyReport> > Post([FromForm] AddOrEditOperationReportDto dto) { var user = await _accountRepository.GetByIdAsync(dto.User); string path = Path.Combine("img/customers", dto.CustomerId.ToString(), "report"); string pathFull = _baseUrl.GetBaseUrl(path); var data = new WeeklyReport { Activity = dto.Activity, DateFinished = dto.DateFinished, DateRequest = dto.DateRequest, Observations = dto.Observations, Priority = dto.Priority, RequestId = dto.RequestId, ResponsibleAreaId = dto.ResponsibleAreaId, Status = dto.Status, CustomerId = dto.CustomerId, User = user, }; if (dto.ImgUploadAfter != null) { string nameFile = _imgService.SaveFile(dto.ImgUploadAfter, pathFull, 1280, 720); if (dto.PhotoPathAfter != null) { await _imgService.DeleteFile(pathFull, dto.PhotoPathAfter); } data.PhotoPathAfter = nameFile; } if (dto.ImgUploadBefore != null) { string nameFile = _imgService.SaveFile(dto.ImgUploadBefore, pathFull, 1280, 720); if (dto.PhotoPathBefore != null) { await _imgService.DeleteFile(pathFull, dto.PhotoPathBefore); } data.PhotoPathBefore = nameFile; } await _genericRepository.CreateAsync(data); return(new CreatedAtRouteResult("GetOperationReport", new { id = data.Id }, data)); }
public async Task <ActionResult <Customer> > Post([FromBody] CustomerPostDto dto) { var entity = _mapper.Map <Customer>(dto); try { string path = ("img/administration/customer"); string pathFull = _baseUrl.GetBaseUrl(path); if (dto.Img != null) { string nameFile = _imgService.SaveFile(dto.Img, pathFull, 600, 600); entity.PhotoPath = nameFile; } var result = await _genericRepository.CreateAsync(entity); return(new CreatedAtRouteResult("GetCustomer", new { id = result.Id }, result)); } catch (Exception e) { return(NotFound(e)); } }
public async Task <ActionResult> UpdateImg(int id, [FromForm] IFormFile img) { var model = await _genericRepository.GetAsyncById(id); string path = Path.Combine("img/customers", model.CustomerId.ToString(), "employee"); string pathFull = _baseUrl.GetBaseUrl(path); if (img != null) { string nameFile = _imgService.SaveFile(img, pathFull, 600, 600); if (model.PhotoPath != null) { await _imgService.DeleteFile(pathFull, model.PhotoPath); } model.PhotoPath = nameFile; } await _genericRepository.UpdateAsync(model); return(NoContent()); }
public async Task <ActionResult> UpdateImg(int id, [FromForm] IFormFile img) { var model = await _genericRepository.GetAsyncById(id); string path = ("img/providers"); string pathFull = _baseUrl.GetBaseUrl(path); if (img != null) { string nameFile = _imgService.SaveFile(img, pathFull, 600, 600); if (model.PathPhoto != null) { await _imgService.DeleteFile(pathFull, model.PathPhoto); } model.PathPhoto = nameFile; } await _genericRepository.UpdateAsync(model); return(NoContent()); }
public async Task <ActionResult <ApplicationUser> > UpdateImg(string id, [FromForm] IFormFile file) { if (id == null) { return(NotFound()); } else { string arrayPath = ("img/Administration/accounts/"); var fullPath = _baseUrl.GetBaseUrl(arrayPath); var user = await _userRepository.GetUserById(id); if (user == null) { return(NotFound()); } if (file != null) { if (user.PhotoPath != "avatar") { await _imgService.DeleteFile(fullPath, user.PhotoPath); } user.PhotoPath = _imgService.SaveFile(file, fullPath, 600, 600); await _userRepository.UpdateImg(user); var pathFile = new ImgPathFile(); pathFile.pathFile = user.PhotoPath; return(Ok(pathFile)); } else { return(BadRequest()); } } }