Example #1
0
        public IHttpActionResult updateItem([FromBody] itemsViewModel model)
        {
            var logInUserName = RequestContext.Principal.Identity.Name;

            try
            {
                if (model.id != null && model.product_name != null && model.catid != null && model.qtyAvailable >= 0 && model.qtyAvailable >= model.qtyReorderAlertValue)
                {
                    var items = db.product.Find(model.id);
                    if (items != null)
                    {
                        ulog.loguserActivities(logInUserName,
                                               "Update item name from '" + items.product_name + "' to '" + model.product_name + "' and item quantity from '" + items.opening_stock_qty + "' to '" + model.qtyAvailable + "' the following");
                        items.product_name                   = model.product_name;
                        items.p_descripition                 = model.desc;
                        items.serial_no                      = model.serial_no;
                        items.cat_id                         = model.catid;
                        items.opening_stock_qty              = model.qtyAvailable;
                        items.stock_reorder_alert_qty        = model.qtyReorderAlertValue;
                        items.item_base_unit                 = model.item_base_unit;
                        items.current_stock_pending_approval = items.opening_stock_qty - items.total_item_allocated_pending_approval;
                        items.unitPrice                      = model.unitPrice;
                        db.SaveChanges();
                        return(Ok());
                    }
                }
                return(Content(HttpStatusCode.NotFound, "Item with id '" + model.id + "'not found"));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex));
            }
        }
Example #2
0
        public IHttpActionResult addItem([FromBody] itemsViewModel model)
        {
            var logInUserName = RequestContext.Principal.Identity.Name;

            try
            {
                if (model.is_Item_In_Store == "yes")
                {
                    if (model.product_name != null && model.catid != null && model.qtyAvailable >= 0 && model.qtyAvailable >= model.qtyReorderAlertValue)
                    {
                        var items = new products();
                        items.id                = "P-" + rd.Next(1000);
                        items.product_name      = model.product_name;
                        items.p_descripition    = model.desc;
                        items.serial_no         = model.serial_no;
                        items.cat_id            = model.catid;
                        items.opening_stock_qty = model.qtyAvailable;
                        items.item_base_unit    = model.item_base_unit;
                        items.total_item_allocated_pending_approval = 0;
                        items.current_stock_pending_approval        = items.opening_stock_qty - items.total_item_allocated_pending_approval;
                        items.stock_reorder_alert_qty = model.qtyReorderAlertValue;
                        items.unitPrice = model.unitPrice;
                        db.product.Add(items);
                        db.SaveChanges();
                        ulog.loguserActivities(logInUserName,
                                               "Added new item '" + items.product_name + "'");
                        return(Ok());
                    }
                }
                else
                {
                    if (model.product_name != null && model.catid != null && model.qtyReorderAlertValue >= 0)
                    {
                        var items = new products();
                        items.id                = "P-" + rd.Next(1000);
                        items.product_name      = model.product_name;
                        items.p_descripition    = model.desc;
                        items.serial_no         = model.serial_no;
                        items.cat_id            = model.catid;
                        items.opening_stock_qty = model.qtyAvailable;
                        items.item_base_unit    = model.item_base_unit;
                        items.total_item_allocated_pending_approval = 0;
                        items.current_stock_pending_approval        = items.opening_stock_qty - items.total_item_allocated_pending_approval;
                        items.stock_reorder_alert_qty = model.qtyReorderAlertValue;
                        items.unitPrice = model.unitPrice;
                        db.product.Add(items);
                        db.SaveChanges();
                        ulog.loguserActivities(logInUserName,
                                               "Added new item '" + items.product_name + "'");
                        return(Ok());
                    }
                }

                return(Content(HttpStatusCode.NotAcceptable, "Some items field are wrongly filled"));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex));
            }
        }