private GenericValidator ValidateDepot(DepotObject depot) { var gVal = new GenericValidator(); try { if (depot.JettyId < 1) { gVal.Code = -1; gVal.Error = "Please select a Depot."; return(gVal); } gVal.Code = 5; return(gVal); } catch (Exception) { gVal.Code = -1; gVal.Error = "Depot Validation failed. Please provide all required fields and try again."; return(gVal); } }
public long UpdateDepot(DepotObject depot) { try { if (depot == null) { return(-2); } var depotEntity = ModelMapper.Map <DepotObject, Depot>(depot); if (depotEntity == null || depotEntity.Id < 1) { return(-2); } using (var db = new ImportPermitEntities()) { db.Depots.Attach(depotEntity); db.Entry(depotEntity).State = EntityState.Modified; db.SaveChanges(); return(depot.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public List <DepotObject> GetDepots() { try { using (var db = new ImportPermitEntities()) { var depots = db.Depots.Where(m => !string.IsNullOrEmpty(m.DepotLicense) && m.ExpiryDate != null && m.ExpiryDate >= DateTime.Now && m.Status == true).ToList(); var depotList = new List <DepotObject>(); //return depots.Select(item => new DepotObject {Name = item.Name, Id = item.Id}).ToList(); foreach (var item in depots) { var depotObj = new DepotObject(); depotObj.Id = item.Id; depotObj.Name = item.Name; depotList.Add(depotObj); } return(depotList); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(new List <DepotObject>()); } }
public long AddDepot(DepotObject depot) { try { if (depot == null) { return(-2); } using (var db = new ImportPermitEntities()) { var depotEntity = new Depot { Name = depot.Name, ImporterId = depot.ImporterId, JettyId = depot.JettyId }; var returnStatus = db.Depots.Add(depotEntity); db.SaveChanges(); return(returnStatus.Id); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public long UpdateDepot(DepotObject depot) { try { return(_depotManager.UpdateDepot(depot)); } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult EditDepot(DepotObject depot) { var gVal = new GenericValidator(); try { var stat = ValidateDepot(depot); if (stat.Code < 1) { return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_depot"] == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var olddepot = Session["_depot"] as DepotObject; if (olddepot == null) { gVal.Code = -1; gVal.Error = "Session has timed out."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } olddepot.Name = depot.Name; olddepot.JettyId = depot.JettyId; var docStatus = new DepotServices().UpdateDepot(olddepot); if (docStatus < 1) { gVal.Code = -1; gVal.Error = docStatus == -3 ? "Depot already exists." : "Depot information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = olddepot.Id; gVal.Error = "Depot information was successfully updated"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Code = -1; gVal.Error = "Depot information could not be updated. Please try again later"; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public List <DepotObject> GetDepots(long userProfileId) { try { using (var db = new ImportPermitEntities()) { var objList = new List <DepotObject>(); //get the inspector's location int zoneId; var employee = db.EmployeeDesks.Where(e => e.EmployeeId == userProfileId).ToList(); if (employee.Any()) { zoneId = employee[0].ZoneId; //get the jettymapping in the zone var jettymappings = db.JettyMappings.Where(j => j.ZoneId == zoneId).ToList(); if (jettymappings.Any()) { foreach (var item in jettymappings) { var depot = db.Depots.Where(d => d.JettyId == item.JettyId).ToList(); if (depot.Any()) { var depotObject = new DepotObject(); depotObject.Id = depot[0].Id; depotObject.Name = depot[0].Name; objList.Add(depotObject); } } } return(objList); } return(new List <DepotObject>()); } } catch (Exception ex) { ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message); return(null); } }
public ActionResult AddDepot(DepotObject depot) { 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 = ValidateDepot(depot); if (validationResult.Code == 1) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var appStatus = new DepotServices().AddDepot(depot); if (appStatus < 1) { validationResult.Code = -1; validationResult.Error = appStatus == -2 ? "Depot upload failed. Please try again." : "The Depot Information already exists"; return(Json(validationResult, JsonRequestBehavior.AllowGet)); } gVal.Code = appStatus; gVal.Error = "Depot was successfully added."; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch (Exception) { gVal.Error = "Depot processing failed. Please try again later"; gVal.Code = -1; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public List <DepotObject> GetDepots(int?itemsPerPage, int?pageNumber, out int countG) { try { if ((itemsPerPage != null && itemsPerPage > 0) && (pageNumber != null && pageNumber >= 0)) { var tpageNumber = (int)pageNumber; var tsize = (int)itemsPerPage; using (var db = new ImportPermitEntities()) { var banks = db.Depots.OrderByDescending(m => m.Id).Include("Importer").Include("Jetty").Skip(tpageNumber).Take(tsize).ToList(); if (!banks.Any()) { countG = 0; return(new List <DepotObject>()); } var newList = new List <DepotObject>(); banks.ForEach(h => { var dpt = new DepotObject { Id = h.Id, Name = h.Name, JettyId = h.Jetty.Id, JettyName = h.Jetty.Name }; var usrs = (from pp in db.People.Where(n => n.ImporterId == h.ImporterId) join tt in db.UserProfiles.Include("AspNetUsers") on pp.Id equals tt.PersonId where tt.IsAdmin select new { tt, pp }).ToList(); if (usrs.Any()) { var usr = usrs[0].tt; var p = usrs[0].pp; if (usr != null && usr.Id > 0 && p.Id > 0) { dpt.UserId = usr.AspNetUsers.ElementAt(0).Id; dpt.LastName = p.FirstName + " " + p.LastName; dpt.PhoneNumber = usr.AspNetUsers.ElementAt(0).PhoneNumber; } } else { dpt.UserId = ""; dpt.PhoneNumber = ""; dpt.LastName = ""; } newList.Add(dpt); }); countG = db.Banks.Count(); return(newList); } } countG = 0; return(new List <DepotObject>()); } catch (Exception ex) { countG = 0; return(new List <DepotObject>()); } }