Esempio n. 1
0
        public static bool Update(SupplierViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new VapeContext())
                {
                    if (model.Id == 0)
                    {
                        Mst_Supplier sup = new Mst_Supplier();
                        sup.SupplierCode = model.SupplierCode;
                        sup.SupplierName = model.SupplierName;
                        sup.Address      = model.Address;
                        sup.Phone        = model.Phone;
                        sup.IsActive     = model.IsActive;
                        db.Mst_Supplier.Add(sup);
                        db.SaveChanges();
                    }
                    else
                    {
                        Mst_Supplier sup = db.Mst_Supplier.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (sup != null)
                        {
                            sup.SupplierCode = model.SupplierCode;
                            sup.SupplierName = model.SupplierName;
                            sup.Address      = model.Address;
                            sup.Phone        = model.Phone;
                            sup.IsActive     = model.IsActive;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }
Esempio n. 2
0
        public static bool Delete(int id)
        {
            bool result = true;

            try
            {
                using (var db = new VapeContext())
                {
                    Mst_Supplier sup = db.Mst_Supplier.Where(o => o.Id == id).FirstOrDefault();
                    if (sup != null)
                    {
                        db.Mst_Supplier.Remove(sup);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                result  = false;
            }
            return(result);
        }