示例#1
0
        public ActionResult DeletePort(long id)
        {
            var gVal = new GenericValidator();

            try
            {
                if (id < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Invalid selection";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }
                var delStatus = new PortServices().DeletePort(id);
                if (delStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Port could not be deleted. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "Port Information was successfully deleted";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
        public ActionResult Create()
        {
            CountryServices              countryServices              = new CountryServices();
            ProjectTypeServices          projectTypeServices          = new ProjectTypeServices();
            ClasificationSocietyServices clasificationSocietyServices = new ClasificationSocietyServices();
            PortServices       portServices       = new PortServices();
            RegionServices     regionServices     = new RegionServices();
            VesselTypeServices vesselTypeServices = new VesselTypeServices();

            ViewBag.LstCountry = countryServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstProjectType = projectTypeServices.GetSelect(null).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstVesselType = vesselTypeServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstClasificationSociety = clasificationSocietyServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstPort = portServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstRegion = regionServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });

            return(View(new VesselViewModel()));
        }
示例#3
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));
            }
        }
示例#4
0
        public ActionResult Edit(int Id)
        {
            CountryServices              countryServices              = new CountryServices();
            ProjectTypeServices          projectTypeServices          = new ProjectTypeServices();
            ClasificationSocietyServices clasificationSocietyServices = new ClasificationSocietyServices();
            PortServices       portServices       = new PortServices();
            RegionServices     regionServices     = new RegionServices();
            VesselTypeServices vesselTypeServices = new VesselTypeServices();
            VesselServices     vesselServices     = new VesselServices();

            VesselViewModel model = new VesselViewModel();

            //Desencriptamos y validamos permisos y existencia
            VesselModel vessel = vesselServices.GetFirst(new VesselModel()
            {
                VesselId = Id
            });

            if (vessel == null || vessel.Company.CompanyId != SessionWeb.User.CompanyId)
            {
                return(RedirectToAction("Unauthorized", "Redirect"));
            }

            model.Vessel             = vessel;
            model.VesselSpecificInfo = vesselServices.GetSpecificInfo(Id);
            model.SpecificInfo       = vesselServices.GetSpecificInfoExtra(Id);
            model.VesselCost         = vesselServices.GetCost(Id);

            ViewBag.LstCountry = countryServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstProjectType = projectTypeServices.GetSelect(null).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstVesselType = vesselTypeServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstClasificationSociety = clasificationSocietyServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstPort = portServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstRegion = regionServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });

            return(View("Create", model));
        }
示例#5
0
        public ActionResult GetPortObjects(JQueryDataTableParamModel param)
        {
            try
            {
                IEnumerable <PortObject> filteredParentMenuObjects;
                var countG = 0;

                var pagedParentMenuObjects = GetPorts(param.iDisplayLength, param.iDisplayStart, out countG);

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    filteredParentMenuObjects = new PortServices().Search(param.sSearch);
                }
                else
                {
                    filteredParentMenuObjects = pagedParentMenuObjects;
                }

                if (!filteredParentMenuObjects.Any())
                {
                    return(Json(new List <PortObject>(), JsonRequestBehavior.AllowGet));
                }

                var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
                Func <PortObject, string> orderingFunction = (c => sortColumnIndex == 1 ? c.Name : c.CountryName);

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                filteredParentMenuObjects = sortDirection == "desc" ? filteredParentMenuObjects.OrderBy(orderingFunction) : filteredParentMenuObjects.OrderByDescending(orderingFunction);

                var displayedPersonnels = filteredParentMenuObjects;

                var result = from c in displayedPersonnels
                             select new[] { Convert.ToString(c.Id), c.Name, c.CountryName };
                return(Json(new
                {
                    param.sEcho,
                    iTotalRecords = countG,
                    iTotalDisplayRecords = countG,
                    aaData = result
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <PortObject>(), JsonRequestBehavior.AllowGet));
            }
        }
示例#6
0
        public List <PortObject> GetPorts()
        {
            try
            {
                var port = new PortServices().GetPorts();


                Session["_port"] = port;

                return(new List <PortObject>());
            }
            catch (Exception)
            {
                return(new List <PortObject>());
            }
        }
示例#7
0
        public ActionResult GetPort(long id)
        {
            try
            {
                var port = new PortServices().GetPort(id);
                if (port == null || port.Id < 1)
                {
                    return(Json(new PortObject(), JsonRequestBehavior.AllowGet));
                }

                Session["_port"] = port;

                return(Json(port, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new PortObject(), JsonRequestBehavior.AllowGet));
            }
        }
示例#8
0
        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));
            }
        }
示例#9
0
        public RequestResult <VesselModel> InsUpdComplete(VesselModel vessel,
                                                          VesselSpecificInfoModel vesselSpecificInfo,
                                                          SpecificInformationModel specificInfo,
                                                          VesselCostModel vesselCost)
        {
            RequestResult <VesselModel> resp = new RequestResult <VesselModel>()
            {
                Status = Status.Success
            };
            SpecificInformationServices specificInfoServices       = new SpecificInformationServices();
            CabinSpecificationServices  cabinSpecificationServices = new CabinSpecificationServices();
            RegionServices     regionServices = new RegionServices();
            PortServices       portServices   = new PortServices();
            TransactionOptions scopeOptions   = new TransactionOptions();

            //scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions))
            {
                try
                {
                    //Ciclo para ir a buscar diferentes puntos en el mapa, en caso de que el q se me asigne de forma aleatoria, se encuentre ya en BD
                    int valLocation = 2;
                    int test        = 1;
                    int cont        = 0;
                    while (valLocation > test && cont <= 100)
                    {
                        //Si se va a insertar, le agregamos un punto en el mapa
                        if (vessel.VesselId == null)
                        {
                            test = 0;
                            PortModel port = portServices.GetById((int)vessel.HomePort.PortId);
                            vessel.Location = regionServices.GetLocation(port.Region.RegionId);
                        }
                        else    //De lo contrario verificamos si ha cambiado su puerto, si cambió le asignamos una nueva locación
                        {
                            test = 1;
                            int?RegionIdAct = portServices.GetById((int)vessel.HomePort.PortId).Region.RegionId;
                            int?RegionIdAnt = GetById((int)vessel.VesselId).HomePort.Region.RegionId;
                            if (RegionIdAnt != RegionIdAct)
                            {
                                vessel.Location = regionServices.GetLocation(RegionIdAct);
                            }
                        }

                        //Verificamos si existe otro Barco en el mismo punto
                        if (vessel.Location.Lat == 0)
                        {
                            test = valLocation;
                        }
                        else
                        {
                            valLocation =
                                Get(new VesselModel()
                            {
                                Location = new LatLng()
                                {
                                    Lat = vessel.Location.Lat,
                                    Lng = vessel.Location.Lng
                                }
                            }).Count();
                        }
                        cont++;
                    }
                    if (cont == 100)
                    {
                        throw new Exception("Se ha alcanzado el número de barcos permitidos para una región");
                    }

                    RequestResult <VesselModel> res1 = InsUpd(vessel);
                    if (res1.Status != Status.Success)
                    {
                        throw new Exception(res1.Message);
                    }

                    vesselSpecificInfo.VesselId       = res1.Data.VesselId;
                    vesselSpecificInfo.UserModifiedId = vessel.UserModifiedId;
                    RequestResult <VesselSpecificInfoModel> res2 = InsUpdSpecificInfo(vesselSpecificInfo);
                    if (res2.Status != Status.Success)
                    {
                        throw new Exception(res2.Message);
                    }

                    specificInfo.MatchableId = res1.Data.VesselId;
                    specificInfo.Type        = SpecificInformationModel.VESSEL_TYPE;
                    RequestResult <SpecificInformationModel> res3 = specificInfoServices.InsUpd(specificInfo);
                    if (res3.Status != Status.Success)
                    {
                        throw new Exception(res3.Message);
                    }

                    List <CabinSpecificationModel>          lstCabins = specificInfo.GetCabinSpecificationList(CabinSpecificationModel.VESSEL_TYPE);
                    RequestResult <CabinSpecificationModel> respC;
                    foreach (CabinSpecificationModel cabin in lstCabins)
                    {
                        respC = cabinSpecificationServices.InsUpd(cabin);
                        if (respC.Status != Status.Success)
                        {
                            throw new Exception(respC.Message);
                        }
                    }

                    vesselCost.VesselId = res1.Data.VesselId;
                    RequestResult <VesselCostModel> res4 = InsUpdCost(vesselCost);
                    if (res4.Status != Status.Success)
                    {
                        throw new Exception(res4.Message);
                    }

                    resp = res1;
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    resp.Status  = Status.Error;
                    resp.Message = ex.Message;
                    ts.Dispose();
                    throw new Exception(ex.Message);
                }
            }

            return(resp);
        }
示例#10
0
 public PortController()
 {
     _portServices = new PortServices();
 }