public ActionResult TransactionOffers(string id) { RequestResult <List <AlertModel> > result = new RequestResult <List <AlertModel> >() { Status = Status.Success }; OfferServices services = new OfferServices(); OfferModel model = new OfferModel(); if (id == "offer") { model.Project.ProjectId = 13; model.Vessel.VesselId = 1; model.ProjectAdmin.PersonId = SessionWeb.User.PersonId; model.UserModifiedId = SessionWeb.User.PersonId; result = services.InsComplete(model); } else if (id == "accept") { model.OfferId = 2; result = services.Accept(model, (int)SessionWeb.User.PersonId); } if (result.Status == Status.Success) { foreach (AlertModel alert in result.Data) { var context = GlobalHost.ConnectionManager.GetHubContext <AlertHub>(); context.Clients.Group(string.Format("P{0}", alert.To)) .newAlert(alert); } } result.Data = null; return(Json(result)); }
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)); }