public ActionResult OrderSend(IndexSelectNotificationsMV test, string pickedPerProvider, int? NotificationId) { // load the Final Approval // int position = 1; // GetSelectIndex().lineCollection.IngredientsList.Where(x => x.ProvidersList.Select(y => y.OrderInList).FirstOrDefault() == position); // var list = GetSelectIndexstring s = pickedPerProvider; int position = pickedPerProvider.LastIndexOf(','); var idProvider = pickedPerProvider.Substring(position + 1); var stringIngredient = pickedPerProvider.Substring(0, position); var idIngredient = from val in stringIngredient.Split(',') select int.Parse(val); var orderList = from orderL in db.ProviderPostIngredients where orderL.ProviderId == idProvider && idIngredient.Contains(orderL.ProviderPostIngredientId) select orderL; // var oo = orderList.ToList(); //Create new standard var order = new Order(); order.CreatedDate = DateTime.Now; order.Status="New"; order.RestaurantId = System.Web.HttpContext.Current.User.Identity.GetUserId(); foreach (var ii in orderList){ var oi = new OrderIngredient(); oi.TotalRequired = ii.TotalRequired; oi.UnitCost = ii.UnitCost; oi.TotalCost = ii.TotalCost; oi.NotificationId = NotificationId.GetValueOrDefault(); oi.IngredientId = ii.IngredientId; order.OrderIngredients.Add(oi); } db.Orders.Add(order); //Save whole entity graph to the database try { db.SaveChanges(); _notification = "Order Sent"; } catch (Exception e) { ModelState.AddModelError("","Error DB"); } /// Lo de arriba esta funcionando int id = NotificationId.GetValueOrDefault(); //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} Notification notification = db.Notifications.Find(id); //if (notification == null) //{ // return HttpNotFound(); //} var objPost = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).GroupBy(x => x.Ingredient.Name).ToList(); var objProviderC = db.ProviderPostIngredients.Where(x => x.IngredientNotify.NotificationId == notification.NotificationId).GroupBy(x => x.ProviderId).Count(); IndexSelectNotificationsMV objPost2 = new IndexSelectNotificationsMV(); ///Origin do not delete objPost2.ProviderCount = objProviderC; foreach (var a in objPost) { IngredientesMv objIng = new IngredientesMv(); int count = 0; foreach (var b in a.OrderByDescending(x => x.ProviderId)) { ProvidersMv objProvider = new ProvidersMv(); objProvider.ProviderName = db.Users.Where(x => x.Id == b.ProviderId).Select(x => x.UserName).FirstOrDefault(); objProvider.ProviderPostIngredientId = b.ProviderPostIngredientId; objProvider.OrderInList = count++; objProvider.IngredientName = b.Ingredient.Name; objProvider.ProviderId = b.ProviderId; objProvider.Picked = (stringIngredient.Contains(b.ProviderPostIngredientId.ToString())) ? true : false; objIng.ProvidersList.Add(objProvider); } objIng.IngredientName = a.Select(x => x.Ingredient.Name).FirstOrDefault(); objPost2.provTop = objIng.ProvidersList; objPost2.IngredientsList.Add(objIng); } GetSelectIndex().lineCollection = objPost2; ViewBag.NotificationId = NotificationId; return RedirectToAction("NotificationDetails", GetSelectIndex().lineCollection); }
public ActionResult ModalOrderSend(int? notificationId) { if (ModelState.IsValid) { var ll = GetSendOrdersession().pPIlocalList; //Create new standard var order = new Order(); order.CreatedDate = DateTime.Now; order.Status = "New"; foreach (var ii in ll) { var oi = new OrderIngredient(); oi.TotalRequired = ii.TotalRequired; oi.UnitCost = ii.UnitCost; oi.TotalCost = ii.TotalCost; oi.NotificationId = notificationId.GetValueOrDefault(); // oi.IngredientId = ii.IngredientId; oi.Ingredient = db.Ingredients.Where(x => x.IngredientId == ii.IngredientId).FirstOrDefault(); order.OrderIngredients.Add(oi); } order.RestaurantId = System.Web.HttpContext.Current.User.Identity.GetUserId(); order.ProviderId = GetSendOrdersession().ProviderId; order.ProviderName = db.Users.Where(c=> c.Id == order.ProviderId).Select(c=> c.UserName).FirstOrDefault(); db.Orders.Add(order); ////var templatePath = @"~/EmailTemplates/OrderEmail.cshtml"; var templatePath = System.IO.File.ReadAllText(HostingEnvironment.MapPath("~/EmailTemplates/OrderEmail.cshtml")); //// var templatePath = File. //string myParsedTemplate = Engine.Razor.RunCompile(templatePath,"OrderEmailCache", order.GetType(), order); // Engine.Razor.Run("OrderEmailCache", typeof(Order), order); // string myParsedTemplate = Engine.Razor.RunCompile(templatePath, "OrderEmailCache", null, order); //*** string myParsedTemplate = Engine.Razor.RunCompile(neHostingEnvironment.MapPath(w LoadedTemplateSource(templatePath), "templateKeyE", typeof(Order), order ); // string template = "Hello @Model.ProviderName, welcome to RazorEngine!"; var myParsedTemplate = Engine.Razor.RunCompile(templatePath, "templateKey", null, order); //Save whole entity graph to the database try { db.SaveChanges(); } catch (Exception e) { ModelState.AddModelError("", "Error DB"); } var sentObj = System.Web.HttpContext.Current.User.Identity.GetUserName(); configSMTPasyncM(myParsedTemplate, sentObj, order.ProviderName); GetSendOrdersession().Clear(); // GetSendOrdersession().justSent = "Notification has been sent to: " + order.ProviderName; TempData["justSent"] = "Notification has been sent to: " + order.ProviderName; GetSendOrdersession().notificationId = notificationId.GetValueOrDefault(); return Json(new { success = true }); } return PartialView("_ModalOrderSend"); }