public bool Update(SubTypeDto subTypeDto) { using (UnitOfWork unitOfWork = new UnitOfWork()) { var result = unitOfWork.SubTypeRepository.GetById(subTypeDto.Id); if (result == null) { return(false); } if (subTypeDto.Title.Equals("Unsorted")) { return(true); } result.Id = subTypeDto.Id; result.IsDeleted = subTypeDto.IsDeleted; result.DeletedOn = subTypeDto.DeletedOn; result.Title = subTypeDto.Title; result.CreatedOn = subTypeDto.CreatedOn; result.CreatorId = subTypeDto.Creator.Id; result.CatalogId = subTypeDto.Catalog.Id; unitOfWork.SubTypeRepository.Update(result); return(unitOfWork.Save()); } }
public bool Create(SubTypeDto subTypeDto) { using (UnitOfWork unitOfWork = new UnitOfWork()) { var subType = new SubType() { Id = subTypeDto.Id, IsDeleted = false, DeletedOn = subTypeDto.DeletedOn, Title = subTypeDto.Title, CreatedOn = DateTime.Now, CreatorId = subTypeDto.Creator.Id, CatalogId = subTypeDto.Catalog.Id }; if (subType.Title.Equals("Unsorted")) { return(true); } unitOfWork.SubTypeRepository.Create(subType); return(unitOfWork.Save()); } }
public bool Delete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { SubType result = unitOfWork.SubTypeRepository.GetById(id); if (result == null) { return(false); } if (result.Title.Equals("Unsorted")) { return(true); } TorrentService torrentService = new TorrentService(); List <TorrentDto> torrents = torrentService.GetAllBySubTypeWithDeleted(id).ToList(); CatalogDto unsortedC = catalogService.GetAllWithTitle("Unsorted").FirstOrDefault(); SubTypeDto unsortedS = GetAllWithTitle(unsortedC.Id, "Unsorted").FirstOrDefault(); foreach (var item in torrents) { item.Catalog = unsortedC; item.SybType = unsortedS; torrentService.Update(item); } unitOfWork.SubTypeRepository.Delete(result); return(unitOfWork.Save()); } }
public IActionResult Create([FromBody] SubTypeDto subType) { if (subTypeService.Create(subType)) { return(NoContent()); } return(BadRequest()); }
public IActionResult Update([FromRoute] int id, [FromBody] SubTypeDto subType) { subType.Id = id; if (subTypeService.Update(subType)) { return(NoContent()); } return(BadRequest()); }
public bool FakeDelete(int id) { using (UnitOfWork unitOfWork = new UnitOfWork()) { Catalog result = unitOfWork.CatalogRepository.GetById(id); if (result == null) { return(false); } if (result.Title.Equals("Unsorted")) { return(true); } TorrentService torrentService = new TorrentService(); SubTypeService subTypeService = new SubTypeService(); List <TorrentDto> torrents = torrentService.GetAllByCatalogWithDeleted(id).ToList(); CatalogDto unsortedC = GetAllWithTitle("Unsorted").FirstOrDefault(); SubTypeDto unsortedS = subTypeService.GetAllWithTitle(unsortedC.Id, "Unsorted").FirstOrDefault(); foreach (var item in torrents) { item.Catalog = unsortedC; item.SybType = unsortedS; torrentService.Update(item); } foreach (var item in subTypeService.GetAllByCatalog(result.Id)) { item.IsDeleted = true; item.DeletedOn = DateTime.Now; subTypeService.Update(item); } result.IsDeleted = true; result.DeletedOn = DateTime.Now; unitOfWork.CatalogRepository.Update(result); return(unitOfWork.Save()); } }