public byte[] GetAgreementReport(int OfferId, int UserId) { byte[] file = null; //get offer data OfferServices OfferServ = new OfferServices(); OfferModel offerData = new OfferModel(); offerData = OfferServ.GetById(OfferId); if (offerData == null) { throw new Exception("NOT_FOUND"); } if (UserId != offerData.VesselAdmin.UserId && UserId != offerData.ProjectAdmin.UserId) { throw new Exception("UNAUTHORIZED"); } if (UserId == offerData.VesselAdmin.UserId) { file = AgreementReportFile(OfferId, (int)TypeUser.Vessel); } else if (UserId == offerData.ProjectAdmin.UserId) { file = AgreementReportFile(OfferId, (int)TypeUser.Project); } return(file); }
public ActionResult OfferTransaction(string id, OfferModel offer) { RequestResult <List <AlertModel> > result = new RequestResult <List <AlertModel> >() { Status = Status.Success }; List <AlertModel> lstAlertToProjectCompany = new List <AlertModel>(); List <AlertModel> lstAlertToVesselCompany = new List <AlertModel>(); OfferServices services = new OfferServices(); AlertTemplateServices templateServices = new AlertTemplateServices(); AlertServices alertServices = new AlertServices(); try { OfferModel val = new OfferModel(); if (offer.OfferId != null) { val = services.GetById((int)offer.OfferId); if (val == null) { throw new Exception("NOT_FOUND"); } } if (id.ToLower() == "offer") { offer.ProjectAdmin.PersonId = SessionWeb.User.PersonId; offer.UserModifiedId = SessionWeb.User.PersonId; result = services.InsComplete(offer); Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("ID", offer.Vessel.VesselId.ToString()); AlertTemplateModel template = templateServices.GetById(8); AlertModel alert = alertServices.GetWithValues(template, values); lstAlertToProjectCompany.Add(alert); //Trick the form how i get the offer val = services.GetById((int)offer.OfferId); } else if (id.ToLower() == "accept") { offer.VesselAdmin.PersonId = SessionWeb.User.PersonId; offer.UserModifiedId = SessionWeb.User.PersonId; result = services.Accept(offer, (int)SessionWeb.User.PersonId); Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("ID", "" + val.Project.ProjectId); AlertTemplateModel template = templateServices.GetById(10); AlertModel alert = alertServices.GetWithValues(template, values); lstAlertToProjectCompany.Add(alert); Dictionary <string, string> values2 = new Dictionary <string, string>(); values2.Add("ID", PersonSessionId.ToString()); AlertTemplateModel template2 = templateServices.GetById(11); AlertModel alert2 = alertServices.GetWithValues(template2, values2); lstAlertToVesselCompany.Add(alert2); } else if (id.ToLower() == "reject") { offer.VesselAdmin.PersonId = SessionWeb.User.PersonId; offer.UserModifiedId = SessionWeb.User.PersonId; result = services.Reject(offer); Dictionary <string, string> values2 = new Dictionary <string, string>(); values2.Add("ID", PersonSessionId.ToString()); AlertTemplateModel template2 = templateServices.GetById(11); AlertModel alert2 = alertServices.GetWithValues(template2, values2); lstAlertToVesselCompany.Add(alert2); } else if (id.ToLower() == "fix") { MessageServices chatServices = new MessageServices(); offer.VesselAdmin.PersonId = SessionWeb.User.PersonId; offer.UserModifiedId = SessionWeb.User.PersonId; if (val.Status == OfferModel.FIX && val.VesselAdmin.PersonId == SessionWeb.User.PersonId) { chatServices.MarkAsReaded( new MessageModel() { ReferenceId = offer.OfferId, From = SessionWeb.User.PersonId }); return(Json(result)); } if (val.Status == OfferModel.NEW) { result = services.Fix(offer); Dictionary <string, string> values = new Dictionary <string, string>(); values.Add("ID", offer.OfferId.ToString()); AlertTemplateModel template = templateServices.GetById(9); AlertModel alert = alertServices.GetWithValues(template, values); alert.To = val.ProjectAdmin.PersonId; result.Data.Add(alert); Dictionary <string, string> values2 = new Dictionary <string, string>(); values2.Add("ID", PersonSessionId.ToString()); AlertTemplateModel template2 = templateServices.GetById(11); AlertModel alert2 = alertServices.GetWithValues(template2, values2); lstAlertToVesselCompany.Add(alert2); } } if (result.Status == Status.Success) { var context = GlobalHost.ConnectionManager.GetHubContext <AlertHub>(); foreach (AlertModel alert in result.Data) { context.Clients.Group(string.Format("P{0}", alert.To)) .newAlert(alert); } foreach (AlertModel alert in lstAlertToProjectCompany) { context.Clients.Group(string.Format("C{0}", val.Project.CompanyId)) .newAlert(alert); } foreach (AlertModel alert in lstAlertToVesselCompany) { context.Clients.Group(string.Format("C{0}", val.Vessel.Company.CompanyId.ToString())) .newAlert(alert); } } } catch (Exception ex) { if (ex.Message == "STATUS_NOT_VALID") { result.Message = "La oferta ya no se encuentra disponible."; result.Status = Status.Error; } else if (ex.Message == "NOT_AVAILABILITY") { result.Message = "El barco seleccionado, no está disponible en las fechas seleccionadas."; result.Status = Status.Warning; } else { throw new Exception(result.Message); } } result.Data = null; return(Json(result)); }