コード例 #1
0
        public void AgregarRol(Rol rol)
        {
            var transaccionDb = db.Database.BeginTransaction();

            try
            {
                var existeRol = db.Roles.FirstOrDefault(rolBuscar => rolBuscar.Nombre.ToUpper() == rol.Nombre.ToUpper());
                if (existeRol != null)
                {
                    throw new ArgumentException($"El rol {rol.Nombre} ya existe");
                }


                db.Roles.Add(rol);
                db.SaveChanges();

                var permisos = db.Permisos.ToList();
                foreach (var permiso in permisos)
                {
                    db.RolesAcceso.Add(new RolAcceso()
                    {
                        rolID = rol.RolID, permisoID = permiso.PermisoID, Agregar = false, Editar = false, Eliminar = false, Ver = false
                    });
                }
                db.SaveChanges();

                transaccionDb.Commit();
            }
            catch (Exception ex)
            {
                transaccionDb.Rollback();
                throw new ArgumentException(ex.Message);
            }
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "TransactionID,Status,DateCreated")] Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                db.Transactions.Add(transaction);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(transaction));
        }
コード例 #3
0
ファイル: CategoryController.cs プロジェクト: wingled22/Inv
        public ActionResult Create([Bind(Include = "CategoryID,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "ProductID,CategoryID,ProductName,QuantityPerUnit,Stocks,Price,Available")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            return(View(product));
        }
コード例 #5
0
 public static int DeleteVendor(int vendorID)
 {
     using (InvContext context = new InvContext())
     {
         Vendor vendor = context.Vendors.FirstOrDefault(x => x.VendorID == vendorID);
         if (vendor != null)
         {
             int quantity = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == vendor.ItemProvided.Name).Quantity;
             //Delete Vendor
             if (quantity <= 0)
             {
                 context.Vendors.Remove(vendor);
                 context.SaveChanges();
             }
             else
             {
                 return(2);
             }
         }
         else
         {
             return(1);
         }
         return(0);
     }
 }
コード例 #6
0
        /// <summary>
        /// Submit the order - save to the database (still editable).
        /// </summary>
        /// <returns></returns>
        public bool Submit()
        {
            if (this.ItemsOrdered.Count == 0)
            {
                Statics.DebugOut("Error: cannot submit an order without an items");
                return(false);
            }


            using (InvContext ctx = new InvContext())
            {
                // ensure the context knows about this item in reference to the database
                ctx.Customers.Attach(this.Customer);

                ctx.Entry(this).State = this.OrderID == default(int) ? EntityState.Added : EntityState.Modified;


                // tell the database that this item already exists or needs to be added

                this.DateOrdered = DateTime.Now;
                this.OrderCode   = "ABC" + Statics.rand.Next(0, 999).ToString().PadLeft(3, '0');

                ctx.SaveChanges();
            }

            return(true);
        }
コード例 #7
0
        public static void AddItem(string name, string description, string price, decimal distributionField)
        {
            using (InvContext context = new InvContext())
            {
                ItemCategory itemCategory = new ItemCategory();
                ItemStock    itemStock    = new ItemStock();
                itemCategory.Name        = name;
                itemCategory.Price       = Convert.ToDecimal(price);
                itemCategory.Description = description;

                itemStock.ItemStored = itemCategory;
                itemStock.Quantity   = 0;
                context.ItemCategories.Add(itemCategory);
                context.ItemStocks.Add(itemStock);
                context.SaveChanges();
            }
        }
コード例 #8
0
        public static bool DeleteItem(string itemName)
        {
            using (InvContext context = new InvContext())
            {
                ItemCategory itemCategory = context.ItemCategories.FirstOrDefault(x => x.Name == itemName);
                ItemStock    itemStock    = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == itemName);

                if (itemCategory != null && itemStock != null)
                {
                    context.ItemCategories.Remove(itemCategory);
                    context.ItemStocks.Remove(itemStock);
                    context.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #9
0
ファイル: PosController.cs プロジェクト: wingled22/Inv
        public JsonResult TransactionCreate()
        {
            Transaction transaction = new Transaction()
            {
                DateCreated = DateTime.Now,
                Status      = false
            };

            if (ModelState.IsValid)
            {
                db.Transactions.Add(transaction);
                db.SaveChanges();

                var last_id = db.Transactions.Max(q => q.TransactionID);
                return(Json(new { last_inserted_id = last_id }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { last_inserted_id = "Error on creating transaction" }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #10
0
        public static bool AddVendor(string nameOfVendorToAdd, string nameOfItem)
        {
            using (InvContext context = new InvContext())
            {
                ItemCategory itemCategory = context.ItemCategories.FirstOrDefault(x => x.Name == nameOfItem);
                int          quantity     = context.ItemStocks.FirstOrDefault(x => x.ItemStored.Name == itemCategory.Name).Quantity;
                if (quantity <= 0)
                {
                    //New vendor
                    Vendor vendor = new Vendor();
                    vendor.Name         = nameOfVendorToAdd;
                    vendor.ItemProvided = itemCategory;

                    context.Vendors.Add(vendor);
                    context.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #11
0
 public virtual void Guardar()
 {
     db.SaveChanges();
 }