private void btnUpdate_Click(object sender, EventArgs e) { using (ShopManagementContext context = new ShopManagementContext()) { _productRepository = new ProductRepository(context); _logProductRepository = new LogProductRepository(context); int userid = Convert.ToInt32(lbl_UserId.Text); var user = context.Users.Where(y => y.Id == userid).FirstOrDefault(); if (String.IsNullOrEmpty(tbx_productName.Text) || String.IsNullOrEmpty(txb_Count.Text) || String.IsNullOrEmpty(txb_Price.Text) || String.IsNullOrEmpty(cmb_Category.Text) || rtb_Description.Text == "") { MessageBox.Show("İzahat hissəsin doldurun"); } else { Product product = new Product() { Id = Convert.ToInt32(dgw_ProductTable.CurrentRow.Cells[0].Value), Name = tbx_productName.Text, CategoryId = Convert.ToInt32(cmb_Category.Text.Split('.')[0]), Price = Convert.ToDecimal(txb_Price.Text), Count = Convert.ToInt32(txb_Count.Text), UserId = user.Id, PhoneNumber = user.Phone, Status = (int)Status.Active, ExpireDate = dtp_Expire.Value }; LogProduct logProduct = new LogProduct() { ProductId = product.Id, Description = rtb_Description.Text, Status = (int)Status.Modified, UserId = user.Id, Date = DateTime.Now }; _productRepository.Update(product); _productRepository.Save(); _logProductRepository.Insert(logProduct); _logProductRepository.Save(); Clear(); if (user.RoleId == (int)Enums.Role.Admin) { GetAllProduct(); } else { GetProductInsertedByUser(); } } } }
private void SortByExpireDate() { using (ShopManagementContext context = new ShopManagementContext()) { _productRepository = new ProductRepository(context); _logProductRepository = new LogProductRepository(context); var list = _productRepository.GetAll(); var user = context.Users.Where(u => u.RoleId == (int)Enums.Role.Admin).FirstOrDefault(); var sortedList = list.Where(p => p.ExpireDate.Day.CompareTo(DateTime.Now.Day) == 0); foreach (var i in sortedList) { i.Status = (int)Enums.Status.Expired; i.Name = i.Name; i.Id = i.Id; i.PhoneNumber = i.PhoneNumber; i.Price = i.Price; i.SoldedCount = i.SoldedCount; i.ExpireDate = i.ExpireDate; i.SoldedTotal = i.SoldedTotal; i.UserId = i.UserId; i.CategoryId = i.CategoryId; i.Count = i.Count; _productRepository.Update(i); _productRepository.Save(); LogProduct logProduct = new LogProduct() { ProductId = i.Id, Description = "İstifadə tarxi bitib", Status = (int)Status.Expired, UserId = user.Id, Date = i.ExpireDate }; _logProductRepository.Insert(logProduct); _logProductRepository.Save(); } } }