public static List <Product> BySearch(string search) { List <Product> result = new List <Product>(); using (var db = new XPosContext()) { result = db.Products .Where(p => p.Active == true && (p.Initial.Contains(search) || p.Name.Contains(search) || p.Description.Contains(search))) .Take(10) .ToList(); } return(result); }
public static ResponseResult Insert(OrderHeader entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XPosContext()) { string newRef = GetNewReference(); OrderHeader oh = new OrderHeader(); oh.Amount = entity.Amount; oh.Reference = newRef; oh.Active = true; oh.CreateBy = "Dimas"; oh.CreateDate = DateTime.Now; db.OrderHeaders.Add(oh); foreach (var item in entity.OrderDetails) { OrderDetail od = new OrderDetail(); //OrderHeader -> Id od.HeaderId = oh.Id; od.ProductId = item.ProductId; od.Price = item.Price; od.Quantity = item.Quantity; od.Active = true; od.CreateBy = "Dimas"; od.CreateDate = DateTime.Now; db.OrderDetails.Add(od); } db.SaveChanges(); entity.Reference = newRef; result.Entity = entity; } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public void TestInsertCategory() { Trace.WriteLine("-- Start Insert Category --"); using (var db = new XPosContext()) { //var listCategory = db.Categories.ToList(); Category category = new Category(); category.Initial = "ManCo"; category.Name = "Main Course"; category.Active = true; category.CreatedBy = "Atur"; category.CreatedDate = DateTime.Now; db.Categories.Add(category); db.SaveChanges(); } Trace.WriteLine("-- End Insert Category --"); }
public void TestInsertVariant() { Trace.WriteLine("-- Start Insert Variant --"); using (var db = new XPosContext()) { //var listCategory = db.Categories.ToList(); Variant variant = new Variant(); variant.CategoryId = 1; variant.Initial = "DSR"; variant.Name = "Desert"; variant.Active = true; variant.CreatedBy = "Atur"; variant.CreatedDate = DateTime.Now; db.Variants.Add(variant); db.SaveChanges(); } Trace.WriteLine("-- End Insert Variant --"); }
public static Category ById(long id) { Category result = new Category(); try { using (var db = new XPosContext()) { result = db.Categories .Where(o => o.Id == id) .FirstOrDefault(); //if (result == null) //{ // result = new Category(); //} } } catch (Exception ex) { throw; } return(result == null ? new Category() : result); }