Ejemplo n.º 1
0
        public ActionResult DeleteVessel(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 VesselServices().DeleteVessel(id);
                if (delStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Vessel could not be deleted. Please try again later.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = 5;
                gVal.Error = "Vessel Information was successfully deleted";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
        public ActionResult VesselsToOffer(int company, int project, int offer)
        {
            VesselServices serv    = new VesselServices();
            var            vessels = serv.VesselAvailableProject(company, project, offer);

            return(Json(vessels, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public ActionResult AddVessel(VesselObject vessel)
        {
            var gVal = new GenericValidator();

            try
            {
                var validationResult = ValidateVessel(vessel);

                if (validationResult.Code == 1)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                vessel.DateAdded = DateTime.Today;
                var appStatus = new VesselServices().AddVessel(vessel);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "Vessel processing failed. Please try again." : "Vessel Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "Vessel was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Vessel processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 4
0
        public bool HasProjectsVesselsCompany(CompanyModel model)
        {
            ProjectServices pSrv    = new ProjectServices();
            var             project = pSrv.GetProjectCollection(new ProjectModel()
            {
                CompanyId = (int)model.CompanyId
            }, new PagerModel(0, 1, "", "")).Data.FirstOrDefault();

            if (project != null)
            {
                return(true);
            }

            VesselServices vSrv   = new VesselServices();
            var            vessel = vSrv.GetFirst(new VesselModel()
            {
                Company = new CompanyModel()
                {
                    CompanyId = model.CompanyId
                }
            });

            if (vessel != null)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public ActionResult EditVessel(VesselObject vessel)
        {
            var gVal = new GenericValidator();

            try
            {
                var stat = ValidateVessel(vessel);

                if (stat.Code < 1)
                {
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (Session["_vessel"] == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var oldvessel = Session["_vessel"] as VesselObject;

                if (oldvessel == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                oldvessel.Name          = vessel.Name.Trim();
                oldvessel.Capacity      = vessel.Capacity;
                oldvessel.IssueDate     = vessel.IssueDate;
                oldvessel.ExpiryDate    = vessel.ExpiryDate;
                oldvessel.VesselLicense = vessel.VesselLicense;
                oldvessel.CompanyName   = vessel.CompanyName;

                var docStatus = new VesselServices().UpdateVessel(oldvessel);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "Vessel already exists." : "Vessel information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldvessel.VesselId;
                gVal.Error = "Vessel information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Vessel information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Transaction(string id, VesselViewModel dataVW)
        {
            VesselModel data = dataVW.Vessel;
            RequestResult <VesselModel> result = new RequestResult <VesselModel>()
            {
                Status = Status.Success, Data = data
            };
            VesselServices vesselServices = new VesselServices();

            try
            {
                if (!ModelState.IsValid)
                {
                    result = new RequestResult <VesselModel>()
                    {
                        Status = Status.Error, Message = localResource.ErrorOnSave
                    }
                }
                ;
                else
                {
                    if (id == "add")
                    {
                        if (Request.Files.Count > 0)
                        {
                            var File = Request.Files[0];
                            data.Image.FileName    = File.FileName;
                            data.Image.ContentType = File.ContentType;
                            data.Image.FileContent = File.InputStream;
                        }

                        data.UserModifiedId = SessionWeb.User.UserId;

                        result = vesselServices.InsUpdComplete(
                            dataVW.Vessel, dataVW.VesselSpecificInfo, dataVW.SpecificInfo, dataVW.VesselCost);
                        result.Data.Image.FileContent = null;
                        if (result.Status != Status.Success)
                        {
                            throw new Exception(string.Format("{0}: {1}", globalResources.SomethingWrong, result.Message));
                        }
                        return(Json(result));
                    }
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }

            return(Json(result));
        }
Ejemplo n.º 7
0
        public ActionResult Vessels(int?companId)
        {
            var company = companId == null ? new CompanyModel() : new CompanyModel()
            {
                CompanyId = UserCompanyId
            };
            VesselServices regSrv = new VesselServices();

            return(Json(regSrv.Get(new VesselModel()
            {
                Company = company
            })));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
0
        public ActionResult Valid(string id, VesselModel data)
        {
            RequestResult <string> result;
            VesselServices         vesselServices = new VesselServices();

            result = vesselServices.Eval(data);

            if (result.Status == Status.Warning)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = result.Message;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 10
0
        public ActionResult GetVesselObjects(JQueryDataTableParamModel param)
        {
            try
            {
                IEnumerable <VesselObject> filteredParentMenuObjects;
                var countG = 0;

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

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

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

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

                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.VesselId), c.CompanyName, c.Name, c.CapacityStr };
                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 <VesselObject>(), JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 11
0
        public JsonResult List(DatatableModel dt, VesselModel filters)
        {
            VesselServices services = new VesselServices();
            PagerModel     pager    = dt.ToPager();

            filters.Company.CompanyId = SessionWeb.User.CompanyId;
            var collection = services.Get(pager, filters);

            return(Json(new
            {
                status = UI.Status.Success,
                sEcho = dt.sEcho,
                iTotalRecords = pager.TotalRecords,
                iTotalDisplayRecords = pager.TotalRecords,
                aaData = collection
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 12
0
        public ActionResult Manage(int Id)
        {
            VesselServices             services       = new VesselServices();
            ReasonAvailabilityServices reasonServices = new ReasonAvailabilityServices();

            ViewBag.LstReason = reasonServices.GetSelect(globalResources.Select).Select(x => new SelectListItem {
                Value = x.Value, Text = x.Text
            });
            ViewBag.LstEstatus = services.GetEstatus();
            VesselModel vessel = services.GetFirst(new VesselModel()
            {
                VesselId = Id
            });

            return(View(new VesselAvailabilityViewModel()
            {
                VesselId = Id, VesselEstatusId = (int)vessel.Status
            }));
        }
Ejemplo n.º 13
0
        public ActionResult GetVessel(long id)
        {
            try
            {
                var vessel = new VesselServices().GetVessel(id);
                if (vessel == null || vessel.VesselId < 1)
                {
                    return(Json(new VesselObject(), JsonRequestBehavior.AllowGet));
                }

                Session["_vessel"] = vessel;

                return(Json(vessel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new VesselObject(), JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 14
0
        public ActionResult AvailabilityTransaction(string id, VesselAvailabilityViewModel data)
        {
            RequestResult <VesselAvailabilityModel> result = new RequestResult <VesselAvailabilityModel>()
            {
                Status = Status.Success, Data = data
            };
            VesselAvailabilityServices availabilityServices = new VesselAvailabilityServices();
            VesselServices             services             = new VesselServices();

            try
            {
                if (id.ToLower() == "add")
                {
                    if (!ModelState.IsValid)
                    {
                        result = new RequestResult <VesselAvailabilityModel>()
                        {
                            Status = Status.Error, Message = localResource.ErrorOnSave
                        }
                    }
                    ;
                    else
                    {
                        result = availabilityServices.InsUpd(data);
                        if (result.Status != Status.Success)
                        {
                            throw new Exception(string.Format("{0}: {1}", globalResources.SomethingWrong, result.Message));
                        }

                        return(Json(result));
                    }
                }
                else if (id.ToLower() == "del")
                {
                    result = availabilityServices.Del((int)data.AvailabilityVesselId);
                    if (result.Status != Status.Success)
                    {
                        throw new Exception(string.Format("{0}: {1}", globalResources.SomethingWrong, result.Message));
                    }

                    return(Json(result));
                }
                else if (id.ToLower() == "status")
                {
                    RequestResult <VesselModel> resultV = new RequestResult <VesselModel>()
                    {
                        Status = Status.Success, Data = data.ToVesselModel()
                    };
                    resultV = services.InsUpd(data.ToVesselModel());
                    if (result.Status != Status.Success)
                    {
                        throw new Exception(string.Format("{0}: {1}", globalResources.SomethingWrong, result.Message));
                    }

                    return(Json(result));
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }

            return(Json(result));
        }
        public ActionResult BulkUpload(HttpPostedFileBase file)
        {
            var gVal = new GenericValidator();

            try
            {
                if (file.ContentLength > 0)
                {
                    const string folderPath = "~/BulkUploads";

                    var fileName = file.FileName;
                    var path     = Server.MapPath(folderPath + "/" + fileName);

                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }

                    file.SaveAs(path);

                    var msg               = string.Empty;
                    var errorList         = new List <long>();
                    var vesselLicenses    = new List <VesselObject>();
                    var successfulUploads = ReadExcelData(path, "Vessels", ref errorList, ref msg, ref vesselLicenses);

                    if (!successfulUploads.Any())
                    {
                        gVal.Code  = -1;
                        gVal.Error = msg;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    if (errorList.Any() && successfulUploads.Any())
                    {
                        var feedbackMessage = successfulUploads.Count + " records were successfully uploaded." +
                                              "\n" + errorList.Count + " record(s) could not be uploaded due to specified/unspecified errors.";
                        if (msg.Length > 0)
                        {
                            feedbackMessage += "<br/>" + msg;
                        }

                        gVal.Code  = -1;
                        gVal.Error = feedbackMessage;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    var saveCount = new VesselServices().AddVessel(vesselLicenses);

                    if (saveCount != vesselLicenses.Count)
                    {
                        var feedbackMessage = saveCount + " records were successfully uploaded." +
                                              "\n" + (vesselLicenses.Count - saveCount) + " record(s) could not be uploaded due to specified/unspecified errors.";
                        if (msg.Length > 0)
                        {
                            feedbackMessage += "<br/>" + msg;
                        }

                        gVal.Code  = -1;
                        gVal.Error = feedbackMessage;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    if (errorList.Any() && !successfulUploads.Any())
                    {
                        var feedbackMessage = errorList.Count + " record(s) could not be uploaded due to specified/unspecified errors.";
                        ViewBag.ErrorCode = -1;

                        if (msg.Length > 0)
                        {
                            feedbackMessage += "<br/>" + msg;
                        }

                        gVal.Code  = -1;
                        gVal.Error = feedbackMessage;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    if (!errorList.Any() && successfulUploads.Any())
                    {
                        var feedbackMessage = successfulUploads.Count + " records were successfully uploaded.";

                        if (msg.Length > 0)
                        {
                            feedbackMessage += "<br/>" + msg;
                        }

                        gVal.Code  = 5;
                        gVal.Error = feedbackMessage;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                }
                gVal.Code  = -1;
                gVal.Error = "The selected file is invalid";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                gVal.Code  = -1;
                gVal.Error = "File processing failed.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }