public VesselViewModel() { Vessel = new VesselModel(); VesselSpecificInfo = new VesselSpecificInfoModel(); SpecificInfo = new SpecificInformationModel(); VesselCost = new VesselCostModel(); }
public async Task ValidateBody(VesselModel vessel) { if (await Context.Body.FirstOrDefaultAsync(b => b.BodyName == vessel.BodyName) == null) { throw new Exception($"Body {vessel.BodyName} of {vessel.Name} doesn't exist!"); } }
public RequestResult <VesselModel> InsUpd(VesselModel model) { RequestResult <VesselModel> ER = new RequestResult <VesselModel>() { Status = Status.Success }; using (var db = new EGULFEntities()) { ObjectParameter Id = new ObjectParameter("VesselId", typeof(int?)); Id.Value = model.VesselId; ER = db.sp_InsUpdVessel(Id, model.Name, model.Imo, model.Country.CountryId, model.YearBuild, model.ClasificationSociety.ClasificationSocietyId, model.ClassNotation, model.ClassValidity, model.VesselType.VesselTypeId, model.HomePort.PortId, model.Image.FileReferenceId, model.Status, model.Location.Lat, model.Location.Lng, model.SuitabilityIds, model.UserModifiedId) .Select(x => new RequestResult <VesselModel>() { Status = (bool)x.IsError ? Status.Error : Status.Success, Message = x.Message, Data = model }).FirstOrDefault(); if (ER.Status == Status.Success) { ER.Data.VesselId = Convert.ToInt32(Id.Value.ToString()); } return(ER); } }
public List <VesselModel> Get(VesselModel filter) { PagerModel pager = new PagerModel(0, Int32.MaxValue - 1, "", ""); VesselDA vesselDA = new VesselDA(); return(vesselDA.Get(pager, filter)); }
public async Task <Domain.Vessel> Put(VesselModel putVessel) { Logger.LogTrace($"Put {putVessel.Name} invoked"); Domain.Vessel Vessel = await VesselBL.Create(putVessel); return(Vessel); }
public async Task <Domain.Vessel> Patch(VesselModel vessel) { Logger.LogTrace($"Patch {vessel.Name} invoked"); Domain.Vessel Vessel = await VesselBL.Update(vessel); return(Vessel); }
public VesselModel GetById(int VesselId) { VesselModel filter = new VesselModel(); filter.VesselId = VesselId; VesselModel resp = GetFirst(filter); return(resp); }
public RequestResult <VesselModel> InsUpd(VesselModel model) { bool isAdd = model.VesselId == null; ImagesServices ImageServ = new ImagesServices(); FileServices FileServ = new FileServices(); VesselDA vesselDA = new VesselDA(); RequestResult <VesselModel> resp = new RequestResult <VesselModel>() { Status = Status.Success }; TransactionOptions scopeOptions = new TransactionOptions(); //scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { try { resp = vesselDA.InsUpd(model); if (model.Image.FileContent != null && model.Image.FileContent.Length > 0) { Stream ProcessedImage = ImageServ.ResizeProfileImage(model.Image.FileContent); ProcessedImage.Position = 0; var FileNameExtension = ".jpg"; model.Image.FileName = "vesselimage-" + model.VesselId + FileNameExtension; var path = "vessels/" + model.VesselId + "/images/"; model.Image.ContentType = "image/jpeg"; model.Image.Path = path; model.Image.FileContent = ProcessedImage; FileServ.SaveFile(model.Image); if (isAdd) { resp = vesselDA.InsUpd(model); } } ts.Complete(); } catch (Exception ex) { ts.Dispose(); resp = new RequestResult <VesselModel>() { Status = Status.Error, Message = ex.Message }; Elmah.ErrorSignal.FromCurrentContext().Raise(ex); throw ex; } } return(resp); }
public HttpResponseMessage VesselChange([FromBody] VesselModel item) { var notifications = _process.Changes(item.Token, item.RateLoading, UpdatedId); foreach (var data in notifications) { Notifications.NotifyClientActivity(data, TypeNotifications.Notifications, $"To change Daily Hire for this vessel {data.Name} {string.Format("{0:C}", data.RateLoading)}", HttpStatusCode.OK, data.Owner); } return(new HttpResponseMessage(HttpStatusCode.OK)); }
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)); }
public VesselModel GetFirst(VesselModel filter) { VesselDA vesselDA = new VesselDA(); PagerModel pager = new PagerModel(0, 1, "", ""); VesselModel resp = Get(pager, filter).FirstOrDefault(); if (resp != null) { resp.Suitability = vesselDA.GetSuitability((int)resp.VesselId); } return(resp); }
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)); }
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)); }
public ActionResult VesselNew(string SubMenuId) { var model = new VesselModel(); #region Check UserGroup when user direct key in URL if (!(_clsGlobal.CheckUserGroup(((ClaimsIdentity)User.Identity).FindFirst("UserGroupCode").Value, Convert.ToInt16(SubMenuId)))) { ViewData["Message"] = "You Have No Access Rights For This Module!, error: Invalid Access Rights"; } #endregion Check UserGroup when user direct key in URL SelectList countryList = new SelectList(_clsGlobal.GetCountry(), "Value", "Text"); ViewData["IsNew"] = true; ViewBag.Country = countryList; return(View(model)); }
public async Task <Vessel> InsertAsync(VesselModel vessel) { await ValidateBody(vessel); var result = await Context.AddAsync(Mapper.Map <VesselEntity>(vessel)); try { await Context.SaveChangesAsync(); } catch (DbUpdateException dbUpdateE) { Console.WriteLine("Something was wrong with the update: " + dbUpdateE.InnerException.Message); } return(Mapper.Map <Vessel>(result.Entity)); }
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)); }
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 })); }
public RequestResult <string> Val(VesselModel model) { RequestResult <string> resp = new RequestResult <string>() { Status = Status.Success }; using (var db = new EGULFEntities()) { var ER = db.sp_ValVessel(model.VesselId, model.Name, model.Imo) .Select(x => new RequestResult <string>() { Status = (bool)x.IsError ? Status.Error : Status.Warning, Message = x.Message, Data = x.Message }).FirstOrDefault(); return(ER ?? resp); } }
public PartialViewResult GetVesselDetails(bool IsView, string SecurityId) { var model = new VesselModel(); SelectList countryList = new SelectList(_clsGlobal.GetCountry(), "Value", "Text"); ViewBag.Country = countryList; SelectList vehicleModel = new SelectList(new List <CommonDropDown>(), "value", "label"); ViewBag.VehicleModel = vehicleModel; SelectList lstType = new SelectList(_clsGlobal.GetListOfValue("SECURITY_ITEM_STATUS", "", "O", "", ""), "Value", "Text"); ViewBag.StatusList = lstType; if (!string.IsNullOrEmpty(SecurityId)) { model = _clsSecurity.GetSecurityVesselDetails(SecurityId, "Security_VesselMortgagor"); } ViewBag.Viewable = IsView; return(PartialView("_VesselPartialView", model)); }
public async Task <Vessel> UpdateAsync(VesselModel vessel) { VesselEntity entity = await Get(vessel); if (entity == null) { throw new Exception("This vessel doesn't exist!"); } await ValidateBody(vessel); entity.Affiliation = vessel.Affiliation; entity.BodyName = vessel.BodyName; entity.DV = vessel.DV; entity.FlightState = vessel.FlightState; Context.Update(entity); await Context.SaveChangesAsync(); return(Mapper.Map <Vessel>(entity)); }
public Task <Vessel> Update(VesselModel vessel) { return(VesselDataAccess.UpdateAsync(vessel)); }
public HttpResponseMessage Put(Guid id, [FromBody] VesselModel item) { _process.Save(item.Token, item.Name, item.Description, item.Phone, item.Email, item.Contact, item.CityId, item.Speed, item.TypeId, item.Capacity, item.Demurrage, item.RateLoading, item.RateUnloading, item.IfoConsumed, item.MgoConsumed, item.Products, item.Property, item.IsActive, UpdatedId); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public RequestResult <string> Eval(VesselModel model) { VesselDA vesselDA = new VesselDA(); return(vesselDA.Val(model)); }
public List <VesselModel> Get(PagerModel pager, VesselModel filter) { VesselDA vesselDA = new VesselDA(); return(vesselDA.Get(pager, filter)); }
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); }
/// <summary> /// Offer from Project to Vessel /// Validations /// Insert offer with Status NEW /// Send alert to Vessel company owners /// Send mail to Vessel company owners /// </summary> /// <param name="offer"></param> /// <returns></returns> public RequestResult <List <AlertModel> > InsComplete(OfferModel offer) { RequestResult <List <AlertModel> > resp = new RequestResult <List <AlertModel> >() { Status = Status.Success }; OfferDA offerDA = new OfferDA(); VesselServices vesselServices = new VesselServices(); PersonServices personServices = new PersonServices(); AlertServices alertServices = new AlertServices(); List <AlertModel> lstAlertToSend = new List <AlertModel>(); MailServices MailServ = new MailServices(); ITemplate factory = new TemplateMessagesFactory(); TransactionOptions scopeOptions = new TransactionOptions(); ////scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions)) { try { if (offer.Vessel.VesselId == null) { throw new Exception("VesselId REQUIRED"); } if (offer.Project.ProjectId == null) { throw new Exception("ProjectId REQUIRED"); } if (offer.ProjectAdmin.PersonId == null) { throw new Exception("ProjectAdmin.PersonId REQUIRED"); } OfferModel val = new OfferModel(); List <OfferModel> lstVal = new List <OfferModel>(); val.Project.ProjectId = offer.Project.ProjectId; val.Vessel.VesselId = offer.Vessel.VesselId; lstVal = Get(val); if (lstVal.Count > 0) { throw new Exception("STATUS_NOT_VALID"); } VesselModel vessel = new VesselModel(); vessel.VesselId = offer.Vessel.VesselId; vessel = vesselServices.Get(vessel).FirstOrDefault(); // Insert offer with Status NEW var respOffer = offerDA.InsUpd(offer); if (respOffer.Status != Status.Success) { throw new Exception(respOffer.Message); } // Send alert to Vessel company owners //Listado de los usuarios de una compañía UserPersonModel person = new UserPersonModel(); person.CompanyId = vessel.Company.CompanyId; List <UserPersonModel> lst = personServices.getUserPerson(person); Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("IMO", vessel.Imo); values.Add("VESSELNAME", vessel.Name); AlertModel alert = alertServices.GetWithValues(6, values); SystemVariableServices SVS = new SystemVariableServices(); Dictionary <string, string[]> param = new Dictionary <string, string[]>(); string EgulfUrl = SVS.GetSystemVariableValue("EgulfWeb"); param.Add("{Enfasis}", new string[] { vessel.Imo, vessel.Name }); param.Add("{Btn_url}", new string[] { EgulfUrl }); foreach (UserPersonModel personItem in lst) { AlertModel alertAux = alert.Clone(); alertAux.To = personItem.PersonId; lstAlertToSend.Add(alertAux); MailServ.SendMail(factory.GetTemplate(personItem.Email, "VesselOfferReceived", param)); } var respAlert = alertServices.InsUpd(lstAlertToSend); if (respAlert != null) { throw new Exception(respAlert.Message); } resp.Data = lstAlertToSend; ts.Complete(); } catch (Exception ex) { ts.Dispose(); resp = new RequestResult <List <AlertModel> >() { Status = Status.Error, Message = ex.Message }; Elmah.ErrorSignal.FromCurrentContext().Raise(ex); throw ex; } } return(resp); }
public VesselEditModel(VesselModel vessel, IEnumerable <BodyModel> bodies) { Vessel = vessel; Bodies = bodies; }
public List <VesselModel> Get(PagerModel pager, VesselModel filter) { if (filter.Location == null) { filter.Location = new LatLng(); } using (var db = new EGULFEntities()) { var resp = db.sp_SelPagVessel( filter.VesselId, filter.Status, filter.Name, filter.Imo, filter.Company.CompanyId, filter.Location.Lat, filter.Location.Lng, pager.Start, pager.Offset, pager.SortBy, pager.SortDir).ToList(); if (resp.Count() > 0) { var first = resp.FirstOrDefault(); pager.TotalRecords = first.TotalRecords.HasValue ? first.TotalRecords.Value : 0; } return((from x in resp select new VesselModel() { VesselId = x.VesselId, Status = x.Status, Name = x.Name, Imo = x.IMO, YearBuild = x.YearBuild, ClassNotation = x.ClassNotation, ClassValidity = x.ClassValidity, VesselType = new VesselTypeModel() { VesselTypeId = x.VesselTypeId, Name = x.VesselType }, HomePort = new PortModel() { PortId = x.PortId, Region = new RegionModel() { RegionId = x.RegionId } }, Image = new FileModel() { FileReferenceId = x.FileReferenceId }, Company = new CompanyModel() { CompanyId = x.CompanyId }, Country = new CountryModel() { CountryId = x.CountryId }, ClasificationSociety = new ClasificationSocietyModel() { ClasificationSocietyId = x.ClasificationSocietyId }, Location = new LatLng() { Lat = (decimal)x.Lat, Lng = (decimal)x.Lng }, }).ToList()); } }
public static Vessel ToEntity(this VesselModel model) { return(AutoMapperConfiguration.Mapper.Map <VesselModel, Vessel>(model)); }
public static Vessel ToEntity(this VesselModel model, Vessel destination) { return(AutoMapperConfiguration.Mapper.Map(model, destination)); }