public ActionResult AddNotificationVessel(NotificationVesselObject notificationVessel) { var gVal = new GenericValidator(); try { var validationResult = ValidateNotificationVessel(notificationVessel); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } notificationVessel.DateAdded = DateTime.Today; var appStatus = new NotificationVesselServices().AddNotificationVessel(notificationVessel); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Notification Vessel processing failed. Please try again." : "Notification Vessel Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Notification Vessel was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Notification Vessel processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public long AddNotificationVessel(NotificationVesselObject vessel) { try { if (vessel == null) { return(-2); } var vesselEntity = ModelMapper.Map <NotificationVesselObject, NotificationVessel>(vessel); if (vesselEntity == null || vesselEntity.NotificationId < 1) { return(-2); } using (var db = new ImportPermitEntities()) { var returnStatus = db.NotificationVessels.Add(vesselEntity); db.SaveChanges(); return(returnStatus.NotificationVesselId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateNotificationVessel(NotificationVesselObject vessel) { try { if (vessel == null) { return(-2); } var vesselEntity = ModelMapper.Map <NotificationVesselObject, NotificationVessel>(vessel); if (vesselEntity == null || vesselEntity.NotificationVesselId < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.NotificationVessels.Attach(vesselEntity); db.Entry(vesselEntity).State = EntityState.Modified; db.SaveChanges(); return(vessel.NotificationVesselId); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateNotificationVessel(NotificationVesselObject notificationVessel) { try { return(_notificationVesselManager.UpdateNotificationVessel(notificationVessel)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditNotificationVessel(NotificationVesselObject notificationVessel) { var gVal = new GenericValidator(); try { var stat = ValidateNotificationVessel(notificationVessel); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_notificationVessel"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldnotificationVessel = Session["_notificationVessel"] as NotificationVesselObject; if (oldnotificationVessel == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldnotificationVessel.Name = notificationVessel.Name.Trim(); oldnotificationVessel.VesselClassTypeId = notificationVessel.VesselClassTypeId; var docStatus = new NotificationVesselServices().UpdateNotificationVessel(oldnotificationVessel); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Notification Vessel already exists." : "Notification Vessel information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = oldnotificationVessel.NotificationVesselId; gVal.Error = "Notification Vessel information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Notification Vessel information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
private GenericValidator ValidateNotificationVessel(NotificationVesselObject notificationVessel) { var gVal = new GenericValidator(); try { if (string.IsNullOrEmpty(notificationVessel.Name)) { gVal.Code = -1; gVal.Error = "Please provide NotificationVessel Name."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "NotificationVessel Validation failed. Please provide all required fields and try again."; return(gVal); } }