public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Oportunidad oportunidad = db.Oportunidad.Find(id); if (oportunidad == null) { return(HttpNotFound()); } if (ApplicationContext.CurrentUser.IsSuperAdmin) { ViewBag.ClienteID = new SelectList(db.Clientes.Include(v => v.Vendedor) .OrderBy(c => c.Nombre), "ClienteID", "Nombre", oportunidad.ClienteID); ViewBag.VendedorID = new SelectList(db.Vendedores.OrderBy(v => v.NombreVendedor), "VendedorID", "NombreVendedor", oportunidad.VendedorID); } else { ViewBag.ClienteID = new SelectList(db.Clientes.Where(c => c.EmpresaID.Equals(ApplicationContext.CurrentUser.EmpresaID)) .OrderBy(c => c.Nombre), "ClienteID", "Nombre", oportunidad.ClienteID); ViewBag.VendedorID = new SelectList(db.Vendedores.Where(v => v.EmpresaID.Equals(ApplicationContext.CurrentUser.EmpresaID)) .OrderBy(v => v.NombreVendedor), "VendedorID", "NombreVendedor", oportunidad.VendedorID); } return(View(oportunidad)); }
/// <summary> /// Delete Object From AjaxJQuery /// </summary> /// <param name="id">PK Value</param> /// <returns></returns> public ActionResult Delete(int id) { try { Oportunidad oportunidad = db.Oportunidad.Find(id); if (oportunidad != null) { var CountCotizacion = db.Cotizacion.Where(c => c.OportunidadID == oportunidad.OportunidadID).Count(); if (CountCotizacion > 0) { return(new JsonResult { Data = new { Message = "No es posible eliminar una oportunidad que tiene cotizaciones asociadas.", Success = false }, ContentEncoding = System.Text.Encoding.UTF8, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } if (oportunidad.Archivos != null && oportunidad.Archivos.Count > 0) { foreach (var archivo in oportunidad.Archivos) { if (System.IO.File.Exists(archivo.LocalUrl)) { try { System.IO.File.Delete(archivo.LocalUrl); } catch { } } } db.OportunidadArchivos.RemoveRange(oportunidad.Archivos); } db.Oportunidad.Remove(oportunidad); db.SaveChanges(); } return(new JsonResult { Data = new { Message = string.Empty, Success = true }, ContentEncoding = System.Text.Encoding.UTF8, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch { return(new JsonResult { Data = new { Message = "Error ejecutando la acción de eliminar. Por favor inténtelo de nuevo", Success = false }, ContentEncoding = System.Text.Encoding.UTF8, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Oportunidad oportunidad = db.Oportunidad.Find(id); if (oportunidad == null) { return(HttpNotFound()); } return(View(oportunidad)); }
internal Guid CrearOportunidad(Oportunidad oportunidad) { Entity entity = new Entity("opportunity"); entity["name"] = oportunidad.Name; entity["msdyn_ordertype"] = new OptionSetValue((int)oportunidad.OrderType); entity["budgetamount"] = new Money(oportunidad.BudgetAmount); entity["estimatedvalue"] = new Money(oportunidad.EstimatedValue); entity["estimatedclosedate"] = oportunidad.EstimatedCloseDate; entity["contactid"] = oportunidad.ContactId; entity["pricelevelid"] = oportunidad.PriceList; entity["transactioncurrencyid"] = oportunidad.TransactionCurrencyId; return(_cnx.service.Create(entity)); }
public static object ToSalesforceEntity(this Oportunidad oportunidad) { try { return(new { info = new { idOportunidad = oportunidad.IdOportunidad, accion = oportunidad.Accion, etapa = oportunidad.Etapa, dkCuenta = oportunidad.DkCuenta.ToString(), unidadNegocio = oportunidad.UnidadNegocio, sucursal = oportunidad.NombreSubcodigo, puntoVenta = oportunidad.PuntoVenta, subcodigo = oportunidad.Subcodigo, fechaOportunidad = oportunidad.FechaOportunidad.ToString("dd/MM/yyyy"), nombreOportunidad = oportunidad.NombreOportunidad, origenOportunidad = oportunidad.OrigenOportunidad, medioOportunidad = oportunidad.MedioOportunidad, gds = oportunidad.GDS, tipoProducto = oportunidad.TipoProducto, rutaViaje = oportunidad.RutaViaje, ciudadOrigen = oportunidad.CiudadOrigen, ciudadDestino = oportunidad.CiudadDestino, tipoRuta = oportunidad.TipoRuta, numPasajeros = oportunidad.NumPasajeros, fechaInicioViaje1 = oportunidad.FechaInicioViaje1.ToString("dd/MM/yyyy"), fechaFinViaje1 = oportunidad.FechaFinViaje1.ToString("dd/MM/yyyy"), fechaInicioViaje2 = oportunidad.FechaInicioViaje2.ToString("dd/MM/yyyy"), fechaFinViaje2 = oportunidad.FechaFinViaje2.ToString("dd/MM/yyyy"), montoEstimado = oportunidad.MontoEstimado, montoReal = oportunidad.MontoReal, pnr1 = oportunidad.Pnr1, pnr2 = oportunidad.Pnr2, motivoPerdida = oportunidad.MotivoPerdida, contacto = oportunidad.Contacto, counterVentas = oportunidad.CounterVentas, counterAdm = oportunidad.CounterAdmin } }); } catch (Exception ex) { throw ex; } }
private Oportunidad BuildOportunidad(Entity entity, ListaDePrecio lista) { string nombre = entity.GetStringValue("fullname"); Oportunidad opportunity = new Oportunidad { Name = $"OPT-{nombre}", OrderType = OrderType.BasadoEnTrabajo, ContactId = new EntityReference("contact", entity.Id), BudgetAmount = 1000, EstimatedValue = 10000, EstimatedCloseDate = DateTime.Now.AddMonths(1), PriceList = new EntityReference("pricelevel", lista.Id), TransactionCurrencyId = new EntityReference("transactioncurrency", lista.TransactionCurrencyId) }; return(opportunity); }
public ActionResult Create([Bind(Exclude = "ArchivosUploader", Include = "OportunidadID,NombreOportunidad,Descripcion,Estado,ClienteID,SolicitadaPor,VendedorID,FechaSolicitud,FechaEntrega,FechaCierre,Valor")] Oportunidad oportunidad) { if (ModelState.IsValid) { if (Request.Files != null && Request.Files.Count > 0) { if (oportunidad.Archivos == null) { oportunidad.Archivos = new List <OportunidadesArchivos>(); } for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileWrapper file = Request.Files[i] as HttpPostedFileWrapper; if (file != null && file.ContentLength > 0) { var fileExtension = Path.GetFileName(file.FileName.Substring(file.FileName.LastIndexOf('.'))); string RelativePath = $"/Uploads/Docs/Opor/{Guid.NewGuid().ToString()}{fileExtension}"; var path = Server.MapPath($"~{RelativePath}"); file.SaveAs(path); oportunidad.Archivos.Add(new OportunidadesArchivos() { Oportunidad = oportunidad, ArchivoNombre = file.FileName, ArchivoUrl = $"{Request.Url.GetLeftPart(UriPartial.Authority)}{RelativePath}", LocalUrl = path }); } } } oportunidad.UserID = ApplicationContext.CurrentUser.Id; db.Oportunidad.Add(oportunidad); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClienteID = new SelectList(db.Clientes.OrderBy(c => c.Nombre), "ClienteID", "Nombre", oportunidad.ClienteID); ViewBag.VendedorID = new SelectList(db.Vendedores.OrderBy(v => v.NombreVendedor), "VendedorID", "NombreVendedor", oportunidad.VendedorID); return(View(oportunidad)); }
public ActionResult Create() { if (ApplicationContext.CurrentUser.IsSuperAdmin) { ViewBag.ClienteID = new SelectList(db.Clientes.OrderBy(c => c.Nombre), "ClienteID", "Nombre"); ViewBag.VendedorID = new SelectList(db.Vendedores.OrderBy(v => v.NombreVendedor), "VendedorID", "NombreVendedor"); } else { ViewBag.ClienteID = new SelectList(db.Clientes.Where(c => c.EmpresaID.Equals(ApplicationContext.CurrentUser.EmpresaID)) .OrderBy(c => c.Nombre), "ClienteID", "Nombre"); ViewBag.VendedorID = new SelectList(db.Vendedores.Where(v => v.EmpresaID.Equals(ApplicationContext.CurrentUser.EmpresaID)) .OrderBy(v => v.NombreVendedor), "VendedorID", "NombreVendedor"); } var o = new Oportunidad(); o.FechaSolicitud = Helpers.DateHelper.GetColombiaDateTime(); return(View(o)); }
public void Execute(IServiceProvider serviceProvider) { try { ServerConnection cnx = new ServerConnection(serviceProvider); CrmRepository crmRepository = new CrmRepository(cnx); Entity entity = (Entity)cnx.context.InputParameters["Target"]; if (!ValidarContexto(entity, cnx)) { return; } ListaDePrecio listaDePrecio = crmRepository.ObtenerListaDePrecios().Find(l => l.Name == "Retail"); Oportunidad opportunity = BuildOportunidad(entity, listaDePrecio); crmRepository.CrearOportunidad(opportunity); } catch (Exception e) { throw new InvalidPluginExecutionException(); } }
public void CreaLaOportunidad() { // Arrange ListaDePrecio listaDePrecio = _crmRepository.ObtenerListaDePrecios().Find(l => l.Name == "Retail"); Oportunidad op = new Oportunidad { Name = $"OPT-Miguel", OrderType = OrderType.BasadoEnTrabajo, ContactId = new EntityReference("contact", new Guid("DFEA0607-1DD2-E811-A963-000D3A3AB6B4")), BudgetAmount = 1000, EstimatedValue = 10000, EstimatedCloseDate = DateTime.Now.AddMonths(1), PriceList = new EntityReference("pricelevel", listaDePrecio.Id), TransactionCurrencyId = new EntityReference("transactioncurrency", listaDePrecio.TransactionCurrencyId) }; // Act Guid result = _crmRepository.CrearOportunidad(op); // Assert Assert.AreNotEqual(default(Guid), result); }