public JsonResult GetNotify(string username) { var account = context.Accounts.Select(x => new { x.Username }).Where(x => x.Username == username).FirstOrDefault(); if (account != null) { // get aprrove Recommend var approveRecommendProduct = context.RecommendProducts.Where(x => x.Username == username && x.IsSeen == false && x.IsApprove == true).ToList(); List<AliasProduct> products = new List<AliasProduct>(); int countAtt = 0; //if have rcmd if (approveRecommendProduct.Count > 0) { foreach (var item in approveRecommendProduct) { countAtt = 0; // take rcmd var newItem = context.AliasProducts.Where(x => x.URL.Contains(item.Parselink) && x.IsActive == true).FirstOrDefault(); if (newItem != null) { //check if confirmed var newProduct = context.Products.FirstOrDefault(x => x.IsActive == true && x.ID == newItem.ProductID && x.TotalWeightPoint > 0); if (newProduct != null) { //check 5 att have var newProductAttribute = context.ProductAttributes.Where(x => x.ProductID == newItem.ProductID).ToList(); if (newProductAttribute != null) { // check if have 5 point of att if (newProductAttribute.Count() >= 5) { foreach (var itemHardware in newProductAttribute) { if (itemHardware.Hardware.WeightCriteraPoint > 0) { countAtt++; } } if (countAtt >= 5) { products.Add(newItem); item.IsSeen = true; context.SaveChanges(); if (item.IsReceive == true && item.IsMailSent == false) { AutoSendMail sendMail = new AutoSendMail(); Task.Factory.StartNew(() => sendMail.AutoSendMailforProduct(item)); return Json(products.Select(product => new { name = product.Name, id = product.ProductID }).ToList(), JsonRequestBehavior.AllowGet); } } } } } } } return Json(products.Select(product => new { name = product.Name, id = product.ProductID }).ToList(), JsonRequestBehavior.AllowGet); } } return Json("NoneData", JsonRequestBehavior.AllowGet); }
// // GET: /Admin/System/ /// <summary> /// Check Role and return page /// </summary> /// <returns></returns> public RedirectToRouteResult WelcomeAreasAdmin() { if (User.IsInRole("staff")) { if (User.Identity.Name.Equals("staff")) { var recommendProducts = context.RecommendProducts.Where(x => x.IsMailSent == false && x.IsReceive == true && x.IsApprove == true).ToList(); AutoSendMail auto = new AutoSendMail(); auto.AutoSendMailforUser(recommendProducts); return RedirectToAction("Index", "TrainingProduct"); }else if (User.Identity.Name.Equals("admin")) { return RedirectToAction("Index", "ManagerUser"); } } if (User.IsInRole("Administrator")) { return RedirectToAction("Index", "ManagerUser"); } return null; }