public long UpdateStepActivityType(StepActivityTypeObject stepActivityType) { try { if (stepActivityType == null) { return(-2); } var stepActivityTypeEntity = ModelMapper.Map <StepActivityTypeObject, StepActivityType>(stepActivityType); if (stepActivityTypeEntity == null || stepActivityTypeEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.StepActivityTypes.Attach(stepActivityTypeEntity); db.Entry(stepActivityTypeEntity).State = EntityState.Modified; db.SaveChanges(); return(stepActivityType.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddStepActivityType(StepActivityTypeObject stepActivityType) { try { if (stepActivityType == null) { return(-2); } var stepActivityTypeEntity = ModelMapper.Map <StepActivityTypeObject, StepActivityType>(stepActivityType); if (stepActivityTypeEntity == null || string.IsNullOrEmpty(stepActivityTypeEntity.Name)) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.StepActivityTypes.Add(stepActivityTypeEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditStepActivityType(StepActivityTypeObject stepActivityType) { 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 = ValidateStepActivityType(stepActivityType); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_stepActivityType"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldstepActivityType = Session["_stepActivityType"] as StepActivityTypeObject; if (oldstepActivityType == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldstepActivityType.Name = stepActivityType.Name.Trim(); //oldstepActivityType.CountryCode = stepActivityType.CountryCode; var docStatus = new StepActivityTypeServices().UpdateStepActivityType(oldstepActivityType); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "StepActivityType already exists." : "StepActivityType information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldstepActivityType.Id; gVal.Error = "StepActivityType information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "StepActivityType information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public long UpdateStepActivityType(StepActivityTypeObject stepActivityType) { try { return(_stepActivityTypeManager.UpdateStepActivityType(stepActivityType)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult AddStepActivityType(StepActivityTypeObject stepActivityType) { 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 = ValidateStepActivityType(stepActivityType); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new StepActivityTypeServices().AddStepActivityType(stepActivityType); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "StepActivityType upload failed. Please try again." : "The StepActivityType Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "StepActivityType was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "StepActivityType processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateStepActivityType(StepActivityTypeObject stepActivityType) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(stepActivityType.Name)) { gVal.Code = -1; gVal.Error = "Please provide StepActivityType."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "StepActivityType Validation failed. Please provide all required fields and try again."; return(gVal); } }