public bool DeleteInformationDeskFile([FromBody] Attachment fileAttachment) { if (fileAttachment == null) { return(false); } //getting the attachment.. var attachment = (AttachmentType)Enum.Parse(typeof(AttachmentType), fileAttachment.AttachmentType); //now lets identify the file and go on to delete.. string folderPath = ""; string urlPath = ""; _generalHelper.GetFolderAndUrlPath(attachment, out folderPath, out urlPath); //when its already in the db... bool deleteActualFile = true; if (fileAttachment.Id > 0) { switch (attachment) { case AttachmentType.GeneralInformation: deleteActualFile = _coreRepository.Delete <GeneralInformationAttachment>(fileAttachment.Id); break; case AttachmentType.InformationDesk: deleteActualFile = _coreRepository.Delete <InformationDeskAttachment>(fileAttachment.Id); break; } } if (!deleteActualFile) { return(false); } //deleeting files... bool isFileDeleted = _generalHelper.DeleteFile(fileAttachment.Name, folderPath); if (fileAttachment.IsImage) { _generalHelper.DeleteFile(fileAttachment.Name, Path.Combine(folderPath, ResourceFolders.Thumbnail.ToString())); } return(isFileDeleted); }
public async Task <IActionResult> DeleteMessage(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var messageFromRepo = await _repo.GetMessage(id); if (messageFromRepo.SenderId == userId) { messageFromRepo.SenderDeleted = true; } else if (messageFromRepo.RecipientId == userId) { messageFromRepo.RecipientDeleted = true; } if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted) { _repo.Delete(messageFromRepo); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Error deleting the message"); }
public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(userId); if (!userFromRepo.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } var photoFromRepo = await _repo.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photoFromRepo.PublicId != null) { var deleteParams = new DeletionParams(photoFromRepo.PublicId); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _repo.Delete(photoFromRepo); } } else { _repo.Delete(photoFromRepo); } if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
public ActionResult StaffResponsibilities(UserInfoViewModel model, string buttonClicked) { if (model.User.Id > 0) { var user = _coreRepo.Get <User>(model.User.Id); model.User = user; List <UserRole> userRoles = user.UserRoles.ToList(); model.UserRoles = userRoles; if (buttonClicked == "Edit") { model.Services = _userManagementRepository.GetActiveServices(InactiveServiceCategories); Service[] services = model.Services as Service[] ?? model.Services.ToArray(); var resposibilities = new List <Responsibility>(); for (int i = 0; i < services.Count(); i++) { resposibilities.Add(new Responsibility { Service = services[i] }); } if (userRoles.Count != 0) { UserRole[] userRolesArray = userRoles.ToArray(); for (int i = 0; i < userRolesArray.Count(); i++) { foreach ( Responsibility res in resposibilities.Where(ress => ress.Service.Id == userRolesArray[i].Role.Service.Id)) { res.Id = userRolesArray[i].Role.Id; res.Type = userRolesArray[i].Role.Type; res.RequiresAccessScope = userRolesArray[i].Role.RequiresAccessScope; res.ServiceId = userRolesArray[i].Role.Service.Id; res.Service = userRolesArray[i].Role.Service; res.CanCreate = userRolesArray[i].Role.CanCreate; res.CanDelete = userRolesArray[i].Role.CanDelete; res.CanRead = userRolesArray[i].Role.CanRead; res.CanUpdate = userRolesArray[i].Role.CanUpdate; } } model.Responsibilities = resposibilities; } else { model.Responsibilities = resposibilities; } return(PartialView("_editStaffResponsibilities", model)); } if (buttonClicked == "Save") { _coreRepo.Delete <UserRole>(user.UserRoles.Select(a => a.Id).ToList()); _coreRepo.Delete <Role>(user.UserRoles.Select(a => a.Role.Id).ToList()); if (model.Responsibilities.Any(a => a.CanRead || a.CanCreate || a.CanUpdate || a.CanDelete)) { foreach ( Responsibility roles in model.Responsibilities.Where(a => a.CanRead || a.CanCreate || a.CanUpdate || a.CanDelete) ) { var newRole = new Role { CanCreate = roles.CanCreate, CanDelete = roles.CanDelete, CanRead = roles.CanRead, CanUpdate = roles.CanUpdate, RequiresAccessScope = roles.RequiresAccessScope, Service = _coreRepo.Get <Service>(roles.Service.Id), //Id = roles.Id }; if (_coreRepo.SaveOrUpdate(newRole)) { var userRole = new UserRole { User = user, Role = newRole }; _coreRepo.SaveOrUpdate(userRole); } ; } } TempData[ApplicationConstants.SuccessNotification] = ApplicationConstants.SuccessSaveMessage; model.UserRoles = _coreRepo.GetAll <UserRole>().Where(a => a.User.Id == model.User.Id).ToList(); return(PartialView("_StaffResponsibilities", model)); //return RedirectToAction("StaffResponsibilities", model); } else { return(PartialView("_StaffResponsibilities", model)); } } return(null); }
public void DeleteEmployee(int id) { _employeeRepository.Delete(a => a.Id == id); }