public JsonResult EditInvoiceSale(Sale sale, List <SalesDetail> salesDetails, List <int> deleted) { PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POS_TutorialEntities db = new POS_TutorialEntities(); retMessage.IsSuccess = true; if (deleted != null) { foreach (var item in deleted) { var data = db.SalesDetails.Where(x => x.SalesDetailId == item).SingleOrDefault();; db.SalesDetails.Remove(data); } } foreach (var item in salesDetails) { if (item.SalesDetailId > 0) { db.Entry(item).State = EntityState.Modified; retMessage.Messagae = "Update Success!"; } else { sale.SalesDetails.Add(new SalesDetail { ProductId = item.ProductId, UnitPrice = item.UnitPrice, Quantity = item.Quantity, LineTotal = item.LineTotal }); var prd = db.ProductStocks.Where(x => x.ProductId == item.ProductId && x.Quantity > 0).FirstOrDefault(); prd.Quantity = prd.Quantity - item.Quantity; db.Entry(prd).State = EntityState.Modified; db.Sales.Add(sale); retMessage.Messagae = "Save Success!"; } } try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveUser(User user) { POS_TutorialEntities db = new POS_TutorialEntities(); bool isSuccess = true; if (user.UserId > 0) { db.Entry(user).State = EntityState.Modified; } else { user.Status = 1; user.Password = AppHelper.GetMd5Hash(user.Password); db.Users.Add(user); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveProduct(Product product) { POS_TutorialEntities db = new POS_TutorialEntities(); bool isSuccess = true; if (product.ProductId > 0) { db.Entry(product).State = EntityState.Modified; } else { product.Status = 1; product.Name = "aaa"; db.Products.Add(product); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveInvoiceSale(Sale sale, List <SalesDetail> salesDetails) { PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POS_TutorialEntities db = new POS_TutorialEntities(); retMessage.IsSuccess = true; foreach (var item in salesDetails) { sale.SalesDetails.Add(new SalesDetail { ProductId = item.ProductId, UnitPrice = item.UnitPrice, Quantity = item.Quantity, LineTotal = item.LineTotal }); var prd = db.ProductStocks.Where(x => x.ProductId == item.ProductId && x.Quantity > 0).FirstOrDefault(); prd.Quantity = prd.Quantity - item.Quantity; db.Entry(prd).State = EntityState.Modified; } db.Sales.Add(sale); retMessage.Messagae = "Save Success!"; try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveProductStock(ProductStock stock) { PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POS_TutorialEntities db = new POS_TutorialEntities(); retMessage.IsSuccess = true; if (stock.ProductQtyId > 0) { db.Entry(stock).State = EntityState.Modified; retMessage.Messagae = "Update Success!"; } else { db.ProductStocks.Add(stock); retMessage.Messagae = "Save Success!"; } try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveBatch(Batch batch) { PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POS_TutorialEntities db = new POS_TutorialEntities(); retMessage.IsSuccess = true; if (batch.BatchId > 0) { db.Entry(batch).State = EntityState.Modified; retMessage.Messagae = "Update Success!"; } else { batch.BatchName = batch.BatchName + db.Batches.Count(); var batchData = db.Batches.Where(x => x.BatchName.Equals(batch.BatchName)).SingleOrDefault(); if (batchData == null) { db.Batches.Add(batch); retMessage.Messagae = "Save Success!"; } else { retMessage.IsSuccess = false; retMessage.Messagae = "This batch already exist!Please refresh and again try!"; } } try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveCategory(Category cat) { POS_TutorialEntities db = new POS_TutorialEntities(); bool isSuccess = true; if (cat.CategoryId > 0) { db.Entry(cat).State = EntityState.Modified; } else { cat.Status = 1; db.Categories.Add(cat); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }