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 <IActionResult> Put(int id, [FromForm] CustomerPostDto dto)
        {
            //var entity = _mapper.Map<Customer>(dto);
            var entity = new Customer()
            {
                Id           = dto.Id,
                NameCustomer = dto.NameCustomer,
                RFC          = dto.RFC,
                PhoneOne     = dto.PhoneOne,
                PhoneTwo     = dto.PhoneTwo,
                Adreess      = dto.Adreess,
                Register     = dto.Register,
                Active       = dto.Active,
                PhotoPath    = dto.PhotoPath
            };

            entity.Id = id;
            string path     = ("img/administration/customer");
            string pathFull = _baseUrl.GetBaseUrl(path);

            if (dto.Img != null)
            {
                string nameFile = _imgService.SaveFile(dto.Img, pathFull, 600, 600);
                if (dto.PhotoPath != null)
                {
                    await _imgService.DeleteFile(pathFull, dto.PhotoPath);
                }
                entity.PhotoPath = nameFile;
            }
            await _genericRepository.UpdateAsync(entity);

            return(NoContent());
        }
        public async Task <ActionResult <Employee> > Delete(int id)
        {
            var model = await _genericRepository.DeleteAsync(id);

            string path     = Path.Combine("img/customers", model.CustomerId.ToString(), "employee");
            string pathFull = _baseUrl.GetBaseUrl(path);

            if (model.PhotoPath != null)
            {
                await _imgService.DeleteFile(pathFull, model.PhotoPath);
            }
            return(NoContent());
        }
        public async Task <ActionResult <Provider> > Delete(int id)
        {
            var model = await _genericRepository.DeleteAsync(id);

            string path     = ("img/providers");
            string pathFull = _baseUrl.GetBaseUrl(path);

            if (model.PathPhoto != null)
            {
                await _imgService.DeleteFile(pathFull, model.PathPhoto);
            }
            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());
                }
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult <WeeklyReport> > Delete(int id)
        {
            var entity = await _genericRepository.GetAsyncById(id);

            await _genericRepository.DeleteAsync(entity);

            var folderCustomer = await _db.Customers.FirstOrDefaultAsync(x => x.Id == entity.CustomerId);

            var folderImg = Path.Combine(_env.WebRootPath, "img/customers", folderCustomer.Id.ToString(), "report");

            if (entity.PhotoPathAfter != null)
            {
                await _imgService.DeleteFile(folderImg, entity.PhotoPathAfter);
            }
            if (entity.PhotoPathBefore != null)
            {
                await _imgService.DeleteFile(folderImg, entity.PhotoPathBefore);
            }
            return(NoContent());
        }