/// <summary> /// Get Campaigns. /// </summary> /// <returns>Campaigns.</returns> public async Task <JsonResult> GetCampaigns() { Response.Expires = 0; //Campañas List <Campaign> answerCampaign = IoCFactoryBusiness.Resolve <ICampaignsService>().GetCampaigns(); if (answerCampaign.Count > 0) { return(Json(new { Items = answerCampaign, Total = answerCampaign.Count, Message = answerCampaign.Count == 0 ? "No hay datos" : string.Empty }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Items = new List <Campaign>(), Total = 0, Mensaje = "No hay datos" }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var respuestaAutenticacion = AuthenticateUser(model.UserName.Trim(), model.Password); if (respuestaAutenticacion != null) { var lstItemsSerialized = JsonSerializer.SerializeObject(new List <Item>()); if ((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData) != null) { lstItemsSerialized = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()).Value; } respuestaAutenticacion.Order.Items = IoCFactoryBusiness.Resolve <IItemsService>().GetItemsByCustomer(respuestaAutenticacion.CustomerId, lstItemsSerialized); await SignInAsync(respuestaAutenticacion, model.RememberMe); return(RedirectToLocal(returnUrl)); } else { //ViewData["MostrarMensaje"] = "Credenciales incorrectas"; ModelState.AddModelError("mensajeError", "Credenciales incorrectas"); } } return(View(model)); }
/// <summary> /// Get the top 5. /// </summary> /// <returns>Top 5.</returns> public async Task <JsonResult> ProductsTop5() { Response.Expires = 0; AnswerPage <Product> answerProduct = new AnswerPage <Product>(); answerProduct = IoCFactoryBusiness.Resolve <IProductsService>().GetProductsTop5(new BaseQueryPagination() { Page = 1, PageSize = 5, Contains = "1" }); if (answerProduct.Results.Count > 0) { return(Json(new { Items = answerProduct.Results, Total = answerProduct.Results.Count, Message = answerProduct.Results.Count == 0 ? "No hay datos" : string.Empty }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Items = new List <Product>(), Total = 0, Mensaje = "No hay datos" }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Detalle de ProductDetail. /// </summary> /// <param name="id">Product identifier.</param> /// <returns>Result.</returns> public ActionResult ProductDetail(int id) { Product product; if (id == 0) { product = new Product() { ProductId = 0, }; } else { product = IoCFactoryBusiness.Resolve <IProductsService>().GetProductById(id).Results.FirstOrDefault(); if (product == null) { ViewData["Result"] = false; ModelState.AddModelError("mensajeError", "product null ."); ViewData["ShowMessage"] = "product null ..."; } } return(View(product)); }
/// <summary> /// Get order. /// </summary> /// <returns></returns> private Order GetOrder() { int userId = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier) == null ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value); var lstItemsSerialized = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()).Value; Order order = IoCFactoryBusiness.Resolve <IOrdersService>().GetOrderByCustomerId(userId, lstItemsSerialized); return(order); }
public async Task <ViewResult> ProductDetail(Product product) { if (ModelState.IsValid) { if (product.Id == 0) { ViewData["Result"] = false; //ViewData["MostrarMensaje"] = "Se debe especificar el id del producto."; ModelState.AddModelError("mensajeError", "Se debe especificar el id del producto."); return(View("Products")); } else { var lstItemsSerialized = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()).Value; int customerId = !User.Identity.IsAuthenticated ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value); lstItemsSerialized = IoCFactoryBusiness.Resolve <IItemsService>().AddItemToCart(product.Id, lstItemsSerialized, customerId); //Guardar en memoria var claims = new List <Claim>(); var thumbClaim = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()); if (thumbClaim != null) { (User.Identity as ClaimsIdentity).RemoveClaim(thumbClaim); } (User.Identity as ClaimsIdentity).AddClaim(new Claim(ClaimTypes.UserData, lstItemsSerialized)); claims = (User.Identity as ClaimsIdentity).Claims.ToList(); var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); if (User.Identity.IsAuthenticated) { AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, id); } } // //ViewData["Resultado"] = true; // return PartialView(model); } ViewData["Result"] = false; return(View("Products")); }
public ActionResult Registry(string accion, CustomerViewModel model) { if (accion.Equals("siguiente")) { if (ModelState.IsValid) { Customer customer = new Customer() { Identification = model.Identification, Names = model.Names, LastNames = model.LastNames, Phone = model.Phone, Email = model.Email, UserName = model.UserName, Password = model.Password, CrediCardType = model.CrediCardType, CreditCardNumber = model.CreditCardNumber, Status = model.Status, Street = model.Street, State = model.State, Zip = model.Zip, Country = model.Country, AddresType = model.AddresType, City = model.City, }; bool answerCustomer = IoCFactoryBusiness.Resolve <ICustomersService>().RegisterCustomer(customer); if (!answerCustomer) { //ViewData["MostrarMensaje"] = "Cliente no registrodo"; ModelState.AddModelError("mensajeError", "Cliente no registrodo"); } else { return(RedirectToAction("Login")); } } } return(View(model)); }
public ActionResult ParameterUpdate(Item item) { if (item == null) { ViewData["Result"] = false; //ViewData["MostrarMensaje"] = "Se debe especificar el id del producto."; ModelState.AddModelError("mensajeError", "Se debe especificar el id del producto."); } else { var lstItemsSerialized = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()).Value; int customerId = !User.Identity.IsAuthenticated ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value); lstItemsSerialized = IoCFactoryBusiness.Resolve <IItemsService>().ModifyQuantityToItem(item, lstItemsSerialized, customerId); //Guardar en memoria var claims = new List <Claim>(); var thumbClaim = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()); if (thumbClaim != null) { (User.Identity as ClaimsIdentity).RemoveClaim(thumbClaim); } (User.Identity as ClaimsIdentity).AddClaim(new Claim(ClaimTypes.UserData, lstItemsSerialized)); claims = (User.Identity as ClaimsIdentity).Claims.ToList(); var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); if (User.Identity.IsAuthenticated) { AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, id); } } ViewData["Result"] = true; return(RedirectToAction("ShoppingCarts")); }
/// <summary> /// Products of a campaign. /// </summary> /// <param name="id">campaign identifier.</param> /// <returns>Result.</returns> public ActionResult CampaignDetail(int id) { List <Product> lstProducts; if (id == 0) { lstProducts = new List <Product>(); } else { List <Product> answerCampaign = IoCFactoryBusiness.Resolve <ICampaignsService>().GetProductsOfCampaignById(id); if (answerCampaign.Count > 0) { return(Json(new { Items = answerCampaign, Total = answerCampaign.Count, Message = answerCampaign.Count == 0 ? "No hay datos" : string.Empty }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Items = new List <Product>(), Total = 0, Mensaje = "No hay datos" }, JsonRequestBehavior.AllowGet)); } if (lstProducts == null) { ViewData["Result"] = false; ModelState.AddModelError("mensajeError", "product null ."); ViewData["ShowMessage"] = "product null ..."; } } return(View(lstProducts)); }
/// <summary> /// Get products. /// </summary> /// <param name="draw">Draw.</param> /// <param name="start">Start.</param> /// <param name="length">Length.</param> /// <param name="search">Search.</param> /// <param name="typeSearch">Type Search.</param> /// <returns>Products.</returns> public async Task <JsonResult> FilterProducts(int draw, int start, int length, Dictionary <string, string> search, TypeSearch typeSearch) { Response.Expires = 0; string filterSearch = string.Empty; if (search.ContainsKey("value")) { filterSearch = search["value"]; } AnswerPage <Product> answerProduct = new AnswerPage <Product>(); answerProduct = IoCFactoryBusiness.Resolve <IProductsService>().GetProducts(filterSearch, start, length, typeSearch); return(Json(new { draw = draw, recordsTotal = answerProduct.Total, recordsFiltered = answerProduct.Total, data = answerProduct.Results }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Perform user authentication. /// </summary> /// <param name="userName">User name.</param> /// <param name="password">User password.</param> /// <returns>Service response.</returns> private Customer AuthenticateUser(string userName, string password) { return(IoCFactoryBusiness.Resolve <ICustomersService>().Authenticate(userName, password)); }
//[AllowAnonymous] public ActionResult ProcessCart(string accion, ShippingInformationViewModel model) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } int customerId = !User.Identity.IsAuthenticated ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value); //var lstItemsSerialized = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()).Value; Order order = new Order() { CustomerId = customerId, ShippingInformation = new ShippingInformation { CrediCardType = model.CrediCardType, CreditCardHolder = model.CreditCardHolder, CreditCardNumber = model.CreditCardNumber, CrediCardExpiration = model.CrediCardExpiration, Names = model.Names, LastNames = model.LastNames, ShippingAddress = model.ShippingAddress, City = model.City, State = model.State, Zip = model.Zip, Country = model.Country } }; var answerOrder = IoCFactoryBusiness.Resolve <IOrdersService>().ProcessOrder(order); if (answerOrder) { var lstItemsSerialized = JsonSerializer.SerializeObject(new List <Item>()); //Guardar en memoria var claims = new List <Claim>(); var thumbClaim = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()); if (thumbClaim != null) { (User.Identity as ClaimsIdentity).RemoveClaim(thumbClaim); } (User.Identity as ClaimsIdentity).AddClaim(new Claim(ClaimTypes.UserData, lstItemsSerialized)); claims = (User.Identity as ClaimsIdentity).Claims.ToList(); var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); if (User.Identity.IsAuthenticated) { AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, id); } ModelState.AddModelError("mensajeError", "Orden procesada correctamente"); } else { ModelState.AddModelError("mensajeError", "No se pudo procesar la orden"); } return(View("ShoppingCarts")); }
public ActionResult ShoppingCarts(string action, Customer model) { //1 validar si no esta autenticado //2 Pedir Datos TC y envio //3 borrar items de BD if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (action.Equals("process")) { Order order = GetOrder(); if (order.Items.Count() == 0) { ModelState.AddModelError("mensajeError", "La orden no tiene productos para procesar"); return(View()); } return(RedirectToAction("ProcessCart")); } if (action.Equals("cancelOrder")) { Order order = GetOrder(); if (order.Items.Count() == 0) { ModelState.AddModelError("mensajeError", "La orden no tiene productos para cancelar"); return(View()); } int customerId = !User.Identity.IsAuthenticated ? 0 : Convert.ToInt32((User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier.ToString()).Value); var result = IoCFactoryBusiness.Resolve <IItemsService>().DeleteItemsByCustomerId(customerId); if (result) { var lstItemsSerialized = JsonSerializer.SerializeObject(new List <Item>()); //Guardar en memoria var claims = new List <Claim>(); var thumbClaim = (User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.UserData.ToString()); if (thumbClaim != null) { (User.Identity as ClaimsIdentity).RemoveClaim(thumbClaim); } (User.Identity as ClaimsIdentity).AddClaim(new Claim(ClaimTypes.UserData, lstItemsSerialized)); claims = (User.Identity as ClaimsIdentity).Claims.ToList(); var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); if (User.Identity.IsAuthenticated) { AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, id); } return(RedirectToAction("ShoppingCarts")); } else { ViewData["subtotal"] = order == null ? 0 : order.Items.Sum(itm => itm.Product.ListPrice * itm.Quantity); ModelState.AddModelError("mensajeError", "No se pudo cancelar la orden"); } } return(View()); }