public string CloseProduct(int product = 0, int ClosingTypeId = 0) { if (ClosingTypeId > 0 && product > 0) { Models.productClosed pcl = new productClosed(); //pcl.closeType = new closeType() { } pcl.ClosingTypeId = ClosingTypeId; pcl.DateTime = DateTime.Now; pcl.ProductId = product; db.productCloseds.Add(pcl); db.SaveChanges(); return("OK"); } return("Not OK"); }
public ActionResult Dasboard(string messageData = "", int product = 0, int ClosingTypeId = 0) { if (ClosingTypeId > 0) { Models.productClosed pcl = new productClosed(); //pcl.closeType = new closeType() { } pcl.ClosingTypeId = ClosingTypeId; pcl.DateTime = DateTime.Now; pcl.ProductId = product; db.productCloseds.Add(pcl); db.SaveChanges(); } if (!string.IsNullOrEmpty(messageData) && product > 0) { Models.message msg = new Models.message(); msg.DateTime = DateTime.Now; msg.Ip = Request.UserHostAddress; msg.message1 = messageData; msg.ProductId = product; msg.UserId = (int)Session["id"]; db.messages.Add(msg); db.SaveChanges(); } int uid = (int)Session["id"]; var messages = db.messages.Where(m => m.UserId == uid || m.product.UserId == uid); List <message> uniqueByProduct = new List <message>(); foreach (var msg in messages) { if (uniqueByProduct.Where(ubp => ubp.ProductId == msg.ProductId).Count() <= 0) { uniqueByProduct.Add(msg); } } return(View(uniqueByProduct.ToList())); }