public int UpdateDocumentType(DocumentTypeObject documentType) { try { if (documentType == null) { return(-2); } var duplicates = _repository.Count(m => m.TypeName.Trim().ToLower() == documentType.TypeName.Trim().ToLower() && (m.DocumentTypeId != documentType.DocumentTypeId)); if (duplicates > 0) { return(-3); } var documentTypeEntity = ModelCrossMapper.Map <DocumentTypeObject, DocumentType>(documentType); if (documentTypeEntity == null || documentTypeEntity.DocumentTypeId < 1) { return(-2); } _repository.Update(documentTypeEntity); _uoWork.SaveChanges(); return(5); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public long AddDocumentType(DocumentTypeObject documentType) { try { if (documentType == null) { return(-2); } var duplicates = _repository.Count(m => m.TypeName.Trim().ToLower() == documentType.TypeName.Trim().ToLower() && (m.DocumentTypeId != documentType.DocumentTypeId)); if (duplicates > 0) { return(-3); } var documentTypeEntity = ModelCrossMapper.Map <DocumentTypeObject, DocumentType>(documentType); if (documentTypeEntity == null || string.IsNullOrEmpty(documentTypeEntity.TypeName)) { return(-2); } var returnStatus = _repository.Add(documentTypeEntity); _uoWork.SaveChanges(); return(returnStatus.DocumentTypeId); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateDocumentType(DocumentTypeObject documentType) { try { if (documentType == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.DocumentTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == documentType.Name.ToLower().Trim().Replace(" ", "") && g.DocumentTypeId != documentType.DocumentTypeId) > 0) { return(-3); } var documentTypeEntity = ModelMapper.Map <DocumentTypeObject, DocumentType>(documentType); if (documentTypeEntity == null || documentTypeEntity.DocumentTypeId < 1) { return(-2); } db.DocumentTypes.Attach(documentTypeEntity); db.Entry(documentTypeEntity).State = EntityState.Modified; db.SaveChanges(); return(documentType.DocumentTypeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddDocumentType(DocumentTypeObject documentType) { try { if (documentType == null) { return(-2); } using (var db = new ImportPermitEntities()) { if (db.DocumentTypes.Count(g => g.Name.ToLower().Trim().Replace(" ", "") == documentType.Name.ToLower().Trim().Replace(" ", "")) > 0) { return(-3); } var documentTypeEntity = ModelMapper.Map <DocumentTypeObject, DocumentType>(documentType); if (documentTypeEntity == null || string.IsNullOrEmpty(documentTypeEntity.Name)) { return(-2); } var returnStatus = db.DocumentTypes.Add(documentTypeEntity); db.SaveChanges(); return(returnStatus.DocumentTypeId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditDocumentType(DocumentTypeObject documentType) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateDocumentType(documentType); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_documentType"] == null) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldDocumentType = Session["_documentType"] as DocumentTypeObject; if (oldDocumentType == null || oldDocumentType.DocumentTypeId < 1) { gVal.Code = -1; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldDocumentType.TypeName = documentType.TypeName.Trim(); if (!string.IsNullOrEmpty(documentType.Description)) { oldDocumentType.Description = documentType.Description.Trim(); } var k = new DocumentTypeServices().UpdateDocumentType(oldDocumentType); if (k < 1) { gVal.Code = -1; gVal.Error = k == -3 ? "Document Type information already exists" : "Document Type information could not be updated. Please try again"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -1; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditDocumentType(DocumentTypeObject documentType) { var gVal = new GenericValidator(); try { if (!ModelState.IsValid) { gVal.Code = -1; gVal.Error = "Plese provide all required fields and try again."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var stat = ValidateDocumentType(documentType); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_DocumentType"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldDocumentType = Session["_DocumentType"] as DocumentTypeObject; if (oldDocumentType == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldDocumentType.Name = documentType.Name.Trim(); var docStatus = new DocumentTypeServices().UpdateDocumentType(oldDocumentType); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Document Type already exists." : "Document Type information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldDocumentType.DocumentTypeId; gVal.Error = "Document Type information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Document Type information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public long UpdateDocumentType(DocumentTypeObject documentType) { try { return(_documentTypeManager.UpdateDocumentType(documentType)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateDocumentType(DocumentTypeObject documentTypeAccount) { try { return(_documentTypeAccountRepository.UpdateDocumentType(documentTypeAccount)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public ActionResult AddDocumentType(DocumentTypeObject documentType) { var gVal = new GenericValidator(); try { if (!ModelState.IsValid) { gVal.Code = -1; gVal.Error = "Plese provide all required fields and try again."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var importerInfo = GetLoggedOnUserInfo(); if (importerInfo.Id < 1) { gVal.Error = "Your session has timed out"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var validationResult = ValidateDocumentType(documentType); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new DocumentTypeServices().AddDocumentType(documentType); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Document Type could not be added. Please try again." : "The Document Type Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Document Type was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Document Type processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateDocumentType(DocumentTypeObject documentType) { var gVal = new GenericValidator(); if (documentType == null) { gVal.Code = -1; gVal.Error = message_Feedback.Fatal_Error; return(gVal); } if (string.IsNullOrEmpty(documentType.TypeName)) { gVal.Code = -1; gVal.Error = "Please provide Document Type Name."; return(gVal); } gVal.Code = 5; gVal.Error = ""; return(gVal); }
public List <DocumentTypeObject> GetDocumentRightsByRoles() { try { var banker = ((int)AppRole.Banker).ToString(); var applicant = ((int)AppRole.Applicant).ToString(); var depotOwner = ((int)AppRole.Depot_Owner).ToString(); using (var db = new ImportPermitEntities()) { var documentTypeRights = db.DocumentTypeRights.Where(m => m.RoleId == banker || m.RoleId == applicant || m.RoleId == depotOwner) .Include("DocumentType") .ToList(); if (!documentTypeRights.Any()) { return(new List <DocumentTypeObject>()); } var objList = new List <DocumentTypeObject>(); documentTypeRights.ForEach(app => { var doc = new DocumentTypeObject() { Name = app.DocumentType.Name, DocumentTypeId = app.DocumentType.DocumentTypeId }; objList.Add(doc); }); return(!objList.Any() ? new List <DocumentTypeObject>() : objList); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(null); } }
private GenericValidator ValidateDocumentType(DocumentTypeObject documentType) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(documentType.Name)) { gVal.Code = -1; gVal.Error = "Please provide Document Type."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "Document Type Validation failed. Please provide all required fields and try again."; return(gVal); } }
public ActionResult AddDocumentType(DocumentTypeObject documentType) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateDocumentType(documentType); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var k = new DocumentTypeServices().AddDocumentType(documentType); if (k < 1) { gVal.Code = -1; gVal.Error = k == -3 ? "Document Type information already exists" : "Document Type information could not be updated. Please try again"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = 5; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -1; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = -1; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }