Esempio n. 1
0
        //Create
        public static ResponseResult Update(Product entity)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XPosContext())
                {
                    if (entity.Id == 0)
                    {
                        // Create
                        entity.Variant    = null;
                        entity.CreateBy   = "Dimas";
                        entity.CreateDate = DateTime.Now;
                        db.Products.Add(entity);
                        db.SaveChanges();
                        result.Message = "Created";
                        result.Entity  = entity;
                    }
                    else
                    {
                        //Edit
                        Product product = db.Products
                                          .Where(o => o.Id == entity.Id)
                                          .FirstOrDefault();
                        if (product == null)
                        {
                            result.Success = false;
                        }
                        else
                        {
                            product.VariantId = entity.VariantId;

                            product.Initial     = entity.Initial;
                            product.Name        = entity.Name;
                            product.Description = entity.Description;
                            product.Price       = entity.Price;
                            product.Stock       = entity.Stock;
                            product.Active      = entity.Active;
                            product.ModifyBy    = "Dimas";
                            product.ModifyDate  = DateTime.Now;
                            db.SaveChanges();

                            result.Message = "Updated";
                            result.Entity  = entity;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
Esempio n. 2
0
        //Create
        public static ResponseResult Update(Variant entity)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XPosContext())
                {
                    if (entity.Id == 0)
                    {
                        // Create
                        entity.CreateBy   = "Dimas";
                        entity.CreateDate = DateTime.Now;
                        db.Variants.Add(entity);
                        db.SaveChanges();
                        result.Message = "Created";
                        result.Entity  = entity;
                    }
                    else
                    {
                        //Edit
                        Variant variant = db.Variants
                                          .Where(o => o.Id == entity.Id)
                                          .FirstOrDefault();
                        if (variant == null)
                        {
                            result.Success = false;
                        }
                        else
                        {
                            variant.CategoryId = entity.CategoryId;

                            variant.Initial    = entity.Initial;
                            variant.Name       = entity.Name;
                            variant.Active     = entity.Active;
                            variant.ModifyBy   = "Dimas";
                            variant.ModifyDate = DateTime.Now;
                            db.SaveChanges();

                            result.Message = "Updated";
                            result.Entity  = entity;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
Esempio n. 3
0
        public static ResponseResult Delete(long id)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XPosContext())
                {
                    Category category = db.Categories
                                        .Where(o => o.Id == id)
                                        .FirstOrDefault();
                    if (category != null)
                    {
                        db.Categories.Remove(category);
                        db.SaveChanges();
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = "Category not found";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Esempio n. 4
0
        public static ResponseResult Update(FileCollection entity)
        {
            ResponseResult result = new ResponseResult();

            try
            {
                using (var db = new XPosContext())
                {
                    if (entity.Id == 0)
                    {
                        entity.CreateBy   = "Dimas";
                        entity.CreateDate = DateTime.Now;

                        db.FileCollections.Add(entity);
                        db.SaveChanges();

                        result.Entity = entity;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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 --");
        }
Esempio n. 7
0
        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 --");
        }