private void ImageRemoveSet(ImageRemove <PagamentoDocumenti> obj) { if (obj.GuidKey == this._INSTANCE_KEY) { if (!SettingDocumentiPagamentiValidator.CheckFolderPdfPagamenti()) { return; } var folderPagamenti = SettingDocumentiPagamentiValidator.ReadSetting().CartellaReteDocumentiPagamenti; using (var saveManager = new SaveEntityManager()) { var repo = saveManager.UnitOfWork.PagamentoDocumentiRepository; var filePdf = obj.File.Entity; var nomeFile = Path.Combine(folderPagamenti, filePdf.PathFile); File.Delete(nomeFile); var item = repo.Find(a => a.ID == filePdf.ID).First(); repo.Delete(item); saveManager.SaveEntity("Rimossa immagine"); } EventAggregator.Instance().Publish <ImageListUpdate>(new ImageListUpdate()); } }
private void ImageRemoveSet(ImageRemove <FotoArticolo> obj) { if (obj.GuidKey == this._INSTANCE_KEY) { EventAggregator.Instance().Publish <ImageArticoloRemove>( new ImageArticoloRemove( FotoSelezionata(), this._controllerImmagini)); } }
public async Task <ActionResult> DeleteEmployee(int?id) { if (id != null) { var current = await dbContext.Employees.Where(x => x.Id == id).FirstOrDefaultAsync(); if (current != null) { if (current.Photo != null) { string fullPath = hostingEnvironment.GetFolder(); ImageRemove.PhotoPathDelete(current.Photo, fullPath); dbContext.Remove(current); } else { dbContext.Remove(current); } await dbContext.SaveChangesAsync(); } } return(RedirectToAction(nameof(AllEmployee))); }
public async Task <ActionResult> EditAppUser(AdminModel adminModel, IFormFile Image) { string Id = HttpContext.Session.GetObjectFromJson <string>("UserId"); AppUser user = userManager.Users.Where(x => x.Id == Id).First(); user.PhoneNumber = adminModel.PhoneNumber; user.FirstName = adminModel.FirstName; user.SecondName = adminModel.SecondName; user.Birth = adminModel.Birthday.ToUniversalTime(); user.Adress = adminModel.Address; if (ModelState.IsValid) { if (adminModel.OldPassword != null) { IList <string> str = await userManager.GetRolesAsync(user); PasswordVerificationResult result = passwordHasher.VerifyHashedPassword(user, user.PasswordHash, adminModel.OldPassword); if (PasswordVerificationResult.Success == result) { if (Image != null) { if (Image.IsFilePhotoFormat()) { string fullPath = hostingEnvironment.GetFolder(); string format = Image.GetFileFormat(); string fileName = nameGenerator.GetFileName(format); string fullFilePath = Path.Combine(fullPath, fileName); await Image.SaveFileAsync(fullFilePath); user.Photo = fileName; ImageRemove.PhotoPathDelete(user.Photo, fullPath); if (adminModel.NewPassword == null) { ModelState.AddModelError("", "New Password empty"); } else { user.PasswordHash = passwordHasher.HashPassword(user, adminModel.NewPassword); dbContext.Update <AppUser>(user); await dbContext.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } } else { ModelState.AddModelError("", "Photo is not Format and format (jpg,png)"); } } else { if (adminModel.NewPassword == null) { ModelState.AddModelError("", "New Password empty"); } else { user.PasswordHash = passwordHasher.HashPassword(user, adminModel.NewPassword); dbContext.Update <AppUser>(user); await dbContext.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } } } else { ModelState.AddModelError("", "Old Password Incorrect"); } } else { IList <string> str = await userManager.GetRolesAsync(user); if (Image != null) { if (Image.IsFilePhotoFormat()) { string fullPath = hostingEnvironment.GetFolder(); string format = Image.GetFileFormat(); string fileName = nameGenerator.GetFileName(format); string fullFilePath = Path.Combine(fullPath, fileName); ImageRemove.PhotoPathDelete(user.Photo, fullPath); await Image.SaveFileAsync(fullFilePath); user.Photo = fileName; dbContext.Update <AppUser>(user); await dbContext.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } else { ModelState.AddModelError("", "Photo is not Format and format (jpg,png)"); } } else { dbContext.Update <AppUser>(user); await dbContext.SaveChangesAsync(); ModelState.AddModelError("", "Succes"); } } } return(View(adminModel)); }
public async Task <ActionResult> EditEmployee(Employee employee, IFormFile Photo) { if (ModelState.IsValid) { Employee data = dbContext.Employees.Where(x => x.Email == employee.Email).FirstOrDefault(); if (data != null) { if (Photo != null) { if (Photo.IsFilePhotoFormat()) { string fullPath = hostingEnvironment.GetFolder(); string format = Photo.GetFileFormat(); string fileName = nameGenerator.GetFileName(format); string fullFilePath = Path.Combine(fullPath, fileName); ImageRemove.PhotoPathDelete(data.Photo, fullPath); await Photo.SaveFileAsync(fullFilePath); data.Name = employee.Name; data.Surname = employee.Surname; data.FatherName = employee.FatherName; data.Gender = employee.Gender; data.IDCardExparyDate = employee.IDCardExparyDate; data.IDCardSerialNumber = employee.IDCardSerialNumber; data.MaritalStatus = employee.MaritalStatus; data.Nationally = employee.Nationally; data.Number = employee.Number; data.Photo = fileName; data.BirthDay = employee.BirthDay; data.DistrictRegistration = employee.DistrictRegistration; data.Email = employee.Email; data.PlasiyerCode = employee.PlasiyerCode; dbContext.Update <Employee>(data); await dbContext.SaveChangesAsync(); } else { ModelState.AddModelError("", "Photo is format (jpg,png)"); } } else { data.Name = employee.Name; data.Surname = employee.Surname; data.FatherName = employee.FatherName; data.Gender = employee.Gender; data.IDCardExparyDate = employee.IDCardExparyDate; data.IDCardSerialNumber = employee.IDCardSerialNumber; data.MaritalStatus = employee.MaritalStatus; data.Nationally = employee.Nationally; data.Number = employee.Number; data.BirthDay = employee.BirthDay; data.DistrictRegistration = employee.DistrictRegistration; data.Email = employee.Email; data.PlasiyerCode = employee.PlasiyerCode; dbContext.Update <Employee>(data); await dbContext.SaveChangesAsync(); } } else { ModelState.AddModelError("", "User is not exists"); } } return(View()); }