Example #1
0
        public ActionResult Associate(Edificio edificio, string submitButton, int?materialId)
        {
            GetAllOptionsMaterial();


            switch (submitButton)
            {
            case "Agregar Material":
                handlerAsocciateMaterial(edificio, false);
                break;

            case "Guardar":
                handlerUpdateAsocciate(edificio);
                return(RedirectToAction("Index"));

            case "Agregar todo":
                handlerAsocciateMaterial(edificio, true);
                break;

            case null:
                var materialToDelete = edificio.EdificiosMateriales.Find(c => c.MaterialId == materialId);
                if (materialToDelete != null)
                {
                    db.Entry(materialToDelete).State = EntityState.Deleted;
                    db.SaveChanges();
                }
                break;

            default:
                break;
            }


            return(View(db.Edificios.Find(edificio.Id)));
        }
Example #2
0
        // GET: Products/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Item item = db.Items.Find(id);

            if (item == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", item.CategoryId);
            ViewBag.StatusId   = new SelectList(db.Statuses, "Id", "Name", item.StatusId);

            db.Entry(item).Collection(i => i.Markups).Load();
            db.Entry(item).Collection(i => i.Inventories).Load();

            foreach (var itemMarkup in item.Markups)
            {
                db.Entry(itemMarkup).Reference(m => m.Price).Load();
            }

            foreach (var itemInventory in item.Inventories)
            {
                db.Entry(itemInventory).Reference(m => m.Location).Load();
            }

            return(View(item));
        }
        public IActionResult Put([Microsoft.AspNetCore.Mvc.FromBody] TeaItem jslot)
        {
            var updateSlot = _context.TeaItems.FirstOrDefault(c => c.Id == jslot.Id);

            if (ModelState.IsValid)
            {
                updateSlot.Id          = jslot.Id;
                updateSlot.ItemName    = jslot.ItemName; //user new input
                updateSlot.CategoryId  = jslot.CategoryId;
                updateSlot.ItemPrice   = jslot.ItemPrice;
                updateSlot.ItemUnit    = jslot.ItemUnit;
                updateSlot.UnitNumber  = jslot.UnitNumber;
                updateSlot.MeasureUnit = jslot.MeasureUnit;
                updateSlot.Sizes       = jslot.Sizes;
                updateSlot.ItemType    = jslot.ItemType;
                updateSlot.ProductDate = jslot.ProductDate;
                updateSlot.StorageDate = jslot.StorageDate;
                updateSlot.ItemTaken   = jslot.ItemTaken;
                updateSlot.Imagepath   = jslot.Imagepath;

                _context.TeaItems.Attach(updateSlot);

                _context.Entry(updateSlot).State = System.Data.Entity.EntityState.Modified;

                _context.SaveChanges();
            }
            return(Json("done"));
        }
Example #4
0
        public async Task <IActionResult> Put([FromBody] TeaCategory jslot)
        {
            var updateSlot = _context.TeaCategorys.FirstOrDefault(c => c.Id == jslot.Id);

            if (ModelState.IsValid)
            {
                updateSlot.Id = jslot.Id;

                updateSlot.CategoryName = jslot.CategoryName;

                updateSlot.SlotNo = jslot.SlotNo;

                updateSlot.SubSlot = jslot.SubSlot;

                _context.TeaCategorys.Attach(updateSlot);

                _context.Entry(updateSlot).State = System.Data.Entity.EntityState.Modified;

                _logger.LogInformation((int)6, "update category from database");

                await _context.SaveChangesAsync();
            }

            return(Json("done"));
        }
Example #5
0
        public async Task <IActionResult> PutInventoryItem(long id, InventoryItem inventoryItem)
        {
            if (id != inventoryItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(inventoryItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InventoryItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public ActionResult Edit([Bind(Include = "Laptop_ID,CATEGORY,Name,CPU,RAM,CPU_MODEL,STORAGE,SCREEN,OS,OTHER_SPEC,PRICE,QTY")] Laptop laptop)
 {
     if (ModelState.IsValid)
     {
         db.Entry(laptop).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(laptop));
 }
Example #7
0
 public ActionResult Edit([Bind(Include = "DateOfReport,IngredientCost,Income,Profit")] WeeklyReport weeklyReport)
 {
     if (ModelState.IsValid)
     {
         db.Entry(weeklyReport).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(weeklyReport));
 }
Example #8
0
        /// <summary>
        ///  Delete record from database
        /// </summary>
        /// <param name="Id">Id to delete record</param>
        public void Delete(int Id)
        {
            TEntity entityToDelete = _dbSet.Find(Id);

            if (_dbContext.Entry(entityToDelete).State == EntityState.Detached)
            {
                _dbSet.Attach(entityToDelete);
            }
            _dbSet.Remove(entityToDelete);
            Save();
        }
 public ActionResult EditProduct(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TestId = new SelectList(db.Tests, "Id", "Name", product.TestId);
     return(View(product));
 }
        public ActionResult Create([Bind(Include = "ID,Name,Price,Meal")] Sandwich sandwich)
        {
            if (ModelState.IsValid)
            {
                db.Sandwiches.Add(sandwich);
                db.SaveChanges();
                db.Entry(sandwich).GetDatabaseValues();
                this.currentID = sandwich.ID;
                return(RedirectToAction("AddIngredients", new { id = sandwich.ID }));
            }

            return(View(sandwich));
        }
Example #11
0
 public virtual void DeleteGeneric <T>(T entity) where T : class
 {
     if (entity is IEntitySoftDeleteBase)
     {
         UpdateGeneric(entity);
         (entity as IEntitySoftDeleteBase).IsDeleted = true;
     }
     else
     {
         Context.Entry(entity).State = EntityState.Deleted;
         Context.Remove(entity);
     }
 }
Example #12
0
        public IActionResult DeleteCategory(int id)
        {
            if (ModelState.IsValid)
            {
                var updateSlot = _context.TeaCategorys.FirstOrDefault(x => x.Id == id);

                _context.Entry(updateSlot).State = System.Data.Entity.EntityState.Deleted;

                _context.SaveChanges();
            }

            return(Json("done"));
        }
Example #13
0
        public ActionResult TakeItemInventory(TestItemInventoryVM vm)
        {
            InventoryContext db        = new InventoryContext();
            Inventory        inventory = db.Inventories.Find(vm.InventoryId);

            foreach (var item in vm.RegularlyOrderedProducts)
            {
                Product product          = db.Products.Find(item.Id);
                var     retrievedInvItem = (from i in db.InventoryItems
                                            where i.ProductId == product.Id && i.InventoryId == inventory.Id
                                            select i).FirstOrDefault();
                InventoryItem invItem = new InventoryItem {
                    Product     = product,
                    ProductId   = product.Id,
                    Inventory   = inventory,
                    InventoryId = inventory.Id,
                    Quantity    = item.UnitsInStock
                };

                //Ensure Quantity has changed before trying to set values
                if (item.UnitsInStock != product.UnitsInStock)
                {
                    invItem.IsInventoried = true;
                }

                //If the InventoryItem is different from what's passed from the view, always take what's passed from the view
                else if (item.IsInventoried != invItem.IsInventoried)
                {
                    invItem.IsInventoried = item.IsInventoried;
                }

                //Set UnitsInStock on Product
                product.UnitsInStock    = item.UnitsInStock;
                db.Entry(product).State = EntityState.Modified;

                //If record exists, update it.
                if (retrievedInvItem != null)
                {
                    db.Entry(retrievedInvItem).CurrentValues.SetValues(invItem);
                }

                //If record doesn't exist, add it
                else
                {
                    db.InventoryItems.Add(invItem);
                }
                db.SaveChanges();
            }
            return(RedirectToAction("TakeInventory"));
        }
Example #14
0
#pragma warning disable CS0436 // Type conflicts with imported type
        public async Task <IActionResult> PutProducts(int id, Products products)
#pragma warning restore CS0436 // Type conflicts with imported type
        {
            if (id != products.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(products).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(Ok(new { result = "success", id }));
        }
        public async Task <IActionResult> PutEntity(int id, Entity entity)
        {
            if (id != entity.EntityID)
            {
                return(BadRequest());
            }

            _context.Entry(entity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #16
0
        public async Task <IActionResult> PutSupplier(int id, Supplier supplier)
        {
            if (id != supplier.SupplierID)
            {
                return(BadRequest());
            }

            _context.Entry(supplier).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplierExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #17
0
        public IHttpActionResult PutDatabase(int id, Model.Database database)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != database.Id)
            {
                return(BadRequest());
            }

            db.Entry(database).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DatabaseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #18
0
        public async Task <ReturnResult> UpdateArticleStock(int articleid, ArticleStock articleStock)
        {
            _context.Entry(articleStock).State = EntityState.Modified;
            ReturnResult result = new ReturnResult();

            try
            {
                if (!ArticleStockExists(articleid))
                {
                    result.UpdatedArticleStock = null;
                    result.StatusMessage       = $"Article ID {articleid} does not exist in the inventory";
                }


                await _context.SaveChangesAsync();

                result.StatusMessage       = $"Article stock updated successfully for article Id - {articleid}";
                result.UpdatedArticleStock = articleStock;
                return(result);
            }
            catch (DbUpdateConcurrencyException e)
            {
                result.StatusMessage = e.Message;
                throw e;
            }
        }
Example #19
0
        public async Task <IActionResult> PutSaintPaulItem([FromRoute] int id, [FromBody] SaintPaulItem saintPaulItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != saintPaulItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(saintPaulItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SaintPaulItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutBoilerPart(long id, BoilerPart boilerPart)
        {
            if (id != boilerPart.Id)
            {
                return(BadRequest());
            }

            _context.Entry(boilerPart).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BoilerPartExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #21
0
        public async Task <IHttpActionResult> PutInventoryFact(int id, InventoryFact inventoryFact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != inventoryFact.Id)
            {
                return(BadRequest());
            }

            db.Entry(inventoryFact).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InventoryFactExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #22
0
        public async Task <IActionResult> PutOrder(long id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #23
0
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.CategoryID)
            {
                return(BadRequest());
            }
            category.ModifiedDate = DateTime.Now;

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutInventoryMaster([FromRoute] int id, [FromBody] InventoryMaster InventoryMaster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != InventoryMaster.InventoryID)
            {
                return(BadRequest());
            }

            _context.Entry(InventoryMaster).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InventoryMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #25
0
        public IHttpActionResult PutServer(string id, Model.Server server)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != server.Id)
            {
                return(BadRequest());
            }

            db.Entry(server).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #26
0
        public static void TakePartToDB(Part part, int techID, string destination, string reason)
        {
            using (var context = new InventoryContext())
            {
                var tech        = context.Tech.Where(x => x.TechID == techID).FirstOrDefault();
                var transaction = new Transaction
                {
                    TechID          = techID,
                    QuickID         = part.QuickID,
                    TransactionType = EnumTransactionType.Take,
                    Quantity        = -1,
                    Destination     = destination,
                    Reason          = reason,
                    TimeStamp       = DateTime.Now,
                };
                context.Transaction.Add(transaction);
                context.Part.Attach(part);


                part.Quantity = (Convert.ToInt32(part.Quantity) - 1).ToString();
                var entry = context.Entry(part);
                entry.Property(x => x.Quantity).IsModified = true;



                context.SaveChanges();
            }
        }
        public async Task <IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.ProductId)
            {
                return(BadRequest());
            }

            _context.Entry(products).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #28
0
        public async Task <ActionResult <ProductInfo> > ChangeProductDescription(string productId, ProductInfo productInfo)
        {
            if (productId != productInfo.ProductId)
            {
                return(null);
            }

            context.Entry(productInfo).State = EntityState.Modified;
            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExist(productId))
                {
                    throw new DbUpdateConcurrencyException();
                }
                else
                {
                    throw;
                }
            }
            return(productInfo);
        }
        public IHttpActionResult PutVirtualDir(int id, VirtualDir virtualDir)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != virtualDir.Id)
            {
                return(BadRequest());
            }

            db.Entry(virtualDir).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VirtualDirExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #30
0
        public async Task <IActionResult> PutUserInfo(UserInfo userInfo, int id)
        {
            if (id != userInfo.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(userInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }