public long UpdateApplicationContent(ApplicationContentObject applicationContent) { try { if (applicationContent == null) { return(-2); } var applicationContentEntity = ModelMapper.Map <ApplicationContentObject, ApplicationContent>(applicationContent); if (applicationContentEntity == null || applicationContentEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.ApplicationContents.Attach(applicationContentEntity); db.Entry(applicationContentEntity).State = EntityState.Modified; db.SaveChanges(); return(applicationContent.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddApplicationContent(ApplicationContentObject applicationContent) { try { if (applicationContent == null) { return(-2); } var applicationContentEntity = ModelMapper.Map <ApplicationContentObject, ApplicationContent>(applicationContent); if (applicationContentEntity == null || string.IsNullOrEmpty(applicationContentEntity.Title)) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.ApplicationContents.Add(applicationContentEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateApplicationContent(ApplicationContentObject applicationContent) { try { return(_applicationContentManager.UpdateApplicationContent(applicationContent)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditApplicationContent(ApplicationContentObject applicationContent) { var gVal = new GenericValidator(); try { var stat = ValidateApplicationContent(applicationContent); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_applicationContent"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldapplicationContent = Session["_applicationContent"] as ApplicationContentObject; if (oldapplicationContent == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldapplicationContent.Title = applicationContent.Title; oldapplicationContent.BodyContent = applicationContent.BodyContent; oldapplicationContent.Href = applicationContent.Href; oldapplicationContent.IsInUse = applicationContent.IsInUse; var docStatus = new ApplicationContentServices().UpdateApplicationContent(oldapplicationContent); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Content already exists." : "Content information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldapplicationContent.Id; gVal.Error = "Content information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Content information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddApplicationContent(ApplicationContentObject applicationContent) { var gVal = new GenericValidator(); try { var importerInfo = GetLoggedOnUserInfo(); if (importerInfo.Id < 1) { gVal.Error = "Your session has timed out"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var validationResult = ValidateApplicationContent(applicationContent); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new ApplicationContentServices().AddApplicationContent(applicationContent); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Content could not be added. Please try again." : "The Content Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Content was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Content processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateApplicationContent(ApplicationContentObject applicationContent) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(applicationContent.Title)) { gVal.Code = -1; gVal.Error = "Please provide Content Title."; return(gVal); } if (string.IsNullOrEmpty(applicationContent.BodyContent)) { gVal.Code = -1; gVal.Error = "Please provide Content Body."; return(gVal); } if (string.IsNullOrEmpty(applicationContent.Href)) { gVal.Code = -1; gVal.Error = "Please provide Content Link/Url."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "Content Validation failed. Please provide all required fields and try again."; return(gVal); } }