public long UpdatePort(PortObject port) { try { if (port == null) { return(-2); } var portEntity = ModelMapper.Map <PortObject, Port>(port); if (portEntity == null || portEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.Ports.Attach(portEntity); db.Entry(portEntity).State = EntityState.Modified; db.SaveChanges(); return(port.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long AddPort(PortObject port) { try { if (port == null) { return(-2); } using (var db = new ImportPermitEntities()) { var portEntity = new Port { Name = port.Name, CountryId = port.CountryId }; var returnStatus = db.Ports.Add(portEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
private GenericValidator ValidatePort(PortObject port) { var gVal = new GenericValidator(); try { if (port.CountryId < 1) { gVal.Code = -1; gVal.Error = "Please select a Country."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "Port Validation failed. Please provide all required fields and try again."; return(gVal); } }
public long UpdatePort(PortObject port) { try { return(_portManager.UpdatePort(port)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditPort(PortObject port) { var gVal = new GenericValidator(); try { var stat = ValidatePort(port); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_port"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldport = Session["_port"] as PortObject; if (oldport == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldport.Name = port.Name; oldport.CountryId = port.CountryId; var docStatus = new PortServices().UpdatePort(oldport); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Port already exists." : "Port information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldport.Id; gVal.Error = "Port information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Port information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public ActionResult AddPort(PortObject port) { 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 = ValidatePort(port); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new PortServices().AddPort(port); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Port upload failed. Please try again." : "The Port Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Port was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Port processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }