public bool UpdateDocumentCategory(DocCategoryVM docCategoryVM) { using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction()) { try { tblDocCategory docCategory = unitOfWork.TblDocCategoryRepository.GetByID(docCategoryVM.DocCategoryID); docCategory.CategoryName = docCategoryVM.CategoryName; docCategory.ModifiedDate = DateTime.Now; docCategory.ModifiedBy = docCategoryVM.ModifiedBy; unitOfWork.TblDocCategoryRepository.Update(docCategory); unitOfWork.Save(); //Complete the Transaction dbTransaction.Commit(); return(true); } catch (Exception ex) { //Roll back the Transaction dbTransaction.Rollback(); return(false); } } }
public List <DocCategoryVM> GetAllDocumentCategories() { try { var docCategoryData = unitOfWork.TblDocCategoryRepository.Get().ToList(); List <DocCategoryVM> docCategoryList = new List <DocCategoryVM>(); foreach (var docCategory in docCategoryData) { DocCategoryVM docCategoryVM = new DocCategoryVM(); docCategoryVM.DocCategoryID = docCategory.DocCategoryID; docCategoryVM.CategoryName = docCategory.CategoryName; docCategoryVM.CreatedDate = docCategory.CreatedDate != null?docCategory.CreatedDate.ToString() : string.Empty; docCategoryVM.ModifiedDate = docCategory.ModifiedDate != null?docCategory.ModifiedDate.ToString() : string.Empty; docCategoryVM.CreatedBy = docCategory.CreatedBy != null?Convert.ToInt32(docCategory.CreatedBy) : 0; docCategoryVM.ModifiedBy = docCategory.ModifiedBy != null?Convert.ToInt32(docCategory.ModifiedBy) : 0; docCategoryList.Add(docCategoryVM); } return(docCategoryList); } catch (Exception ex) { throw; } }
public IHttpActionResult SaveDocumentCategory([FromBody] JObject data) { try { string categoryName = !string.IsNullOrEmpty(data.SelectToken("CategoryName").Value <string>()) ? data.SelectToken("CategoryName").Value <string>() : string.Empty; int userID = !string.IsNullOrEmpty(data.SelectToken("UserID").Value <string>()) ? Convert.ToInt32(data.SelectToken("UserID").Value <string>()) : 0; if (!manageDocument.IsDocumentCategoryAvailable(null, categoryName)) { DocCategoryVM docCategoryVM = new DocCategoryVM(); docCategoryVM.CategoryName = categoryName; docCategoryVM.CreatedBy = userID; bool status = manageDocument.SaveDocumentCategory(docCategoryVM); if (status) { return(Json(new { status = true, message = "Successfully Saved" })); } else { return(Json(new { status = false, message = "Save Failed" })); } } else { return(Json(new { status = false, message = "Document Category Name already exists" })); } } catch (Exception ex) { return(Json(new { status = false, message = "Unknown error occurred" })); } }
public DocCategoryVM GetDocumentCategoryByID(int docCategoryID) { try { var docCategoryData = unitOfWork.TblDocCategoryRepository.GetByID(docCategoryID); DocCategoryVM docCategoryVM = new DocCategoryVM(); docCategoryVM.DocCategoryID = docCategoryData.DocCategoryID; docCategoryVM.CategoryName = docCategoryData.CategoryName; docCategoryVM.CreatedDate = docCategoryData.CreatedDate != null?docCategoryData.CreatedDate.ToString() : string.Empty; docCategoryVM.ModifiedDate = docCategoryData.ModifiedDate != null?docCategoryData.ModifiedDate.ToString() : string.Empty; docCategoryVM.CreatedBy = docCategoryData.CreatedBy != null?Convert.ToInt32(docCategoryData.CreatedBy) : 0; docCategoryVM.ModifiedBy = docCategoryData.ModifiedBy != null?Convert.ToInt32(docCategoryData.ModifiedBy) : 0; return(docCategoryVM); } catch (Exception ex) { throw; } }