Example #1
0
        public JsonNetResult AddItem(string collection)
        {
            //server response
            obj_ServerResponse response = new obj_ServerResponse();
            int affectedRows            = 0;

            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            mdl_Item             item           = jsonSerializer.Deserialize <mdl_Item>(collection);
            var context = new ValidationContext(item);
            var results = new List <ValidationResult>();

            if (Validator.TryValidateObject(item, context, results, true))
            {
                //validate existing vendor item number
                IQueryable <gp_InventoryItems> existingItems = db.gp_InventoryItems.Where(d => d.VNDITNUM == item.VendorItemNumber);
                if (existingItems.Count() > 0)
                {
                    response.MessageType = "warning";
                    response.Message     = "An item already has that vendor code, try again!";
                    response.ShowDialog  = true;

                    return(new JsonNetResult(response));
                }

                gp_InventoryItems dbItem = new gp_InventoryItems();
                dbItem.VNDITNUM    = item.VendorItemNumber;
                dbItem.VNDITDSC    = item.VendorItemDescription;
                dbItem.CustomItem  = true;
                dbItem.DateCreated = DateTime.Now;

                db.gp_InventoryItems.Add(dbItem);
                affectedRows = db.SaveChanges();

                if (affectedRows > 0)
                {
                    response.MessageType = "success";
                    response.Message     = "Item added successfully!";
                    response.ShowDialog  = true;
                }
                else
                {
                    response.MessageType = "danger";
                    response.Message     = "There was a problem saving this item!";
                    response.ShowDialog  = true;
                }
            }
            else
            {
                response.Errors = results.Select(d => new KeyValuePair <string, string>(d.MemberNames.First().ToString(), d.ErrorMessage));
            }

            return(new JsonNetResult(response));
        }
Example #2
0
        // GET:/Forecast/Details/1
        /// <summary>
        /// Returns consumption reports
        /// </summary>
        /// <param name="id">Item Id</param>
        /// <param name="m">Month clicked</param>
        /// <returns>Consumption Report</returns>
        public ActionResult Details(int id, int m)
        {
            if (!WebSecurity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }
            obj_ServerResponse response = new obj_ServerResponse();

            ViewBag.ItemId = id;
            ViewBag.Month  = m;

            return(PartialView());
        }
Example #3
0
        public ActionResult DeleteItem(int id)
        {
            //server response
            obj_ServerResponse response = new obj_ServerResponse();
            int affectedRows            = 0;

            gp_InventoryItems dbItem = db.gp_InventoryItems.Find(id);

            if (id < 1 || dbItem == null)
            {
                //item not found
                response.MessageType = "warning";
                response.Message     = "Item not found!";
                response.ShowDialog  = true;
            }

            //only delete custom, unsynced items
            if (dbItem.CustomItem != true || dbItem.Synced == true)
            {
                //item not found
                response.MessageType = "warning";
                response.Message     = "Can't delete this item!";
                response.ShowDialog  = true;
                return(new JsonNetResult(response));
            }

            db.gp_InventoryItems.Remove(dbItem);
            affectedRows = db.SaveChanges();

            if (affectedRows > 0)
            {
                response.MessageType = "success";
                response.Message     = "Item deleted successfully!";
                response.ShowDialog  = true;
            }
            else
            {
                response.MessageType = "warning";
                response.Message     = "There was a problem deleting this item!";
                response.ShowDialog  = true;
            }

            return(new JsonNetResult(response));
        }
Example #4
0
        public JsonNetResult Details(string collection)
        {
            //server response
            obj_ServerResponse response = new obj_ServerResponse();

            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            mdl_ForecastRevision details        = jsonSerializer.Deserialize <mdl_ForecastRevision>(collection);
            var context = new ValidationContext(details);
            var results = new List <ValidationResult>();

            if (Validator.TryValidateObject(details, context, results, true))
            {
            }
            else
            {
                response.Errors = results.Select(d => new KeyValuePair <string, string>(d.MemberNames.First().ToString(), d.ErrorMessage));
            }

            return(new JsonNetResult());
        }
Example #5
0
        public JsonNetResult EditItem(string collection)
        {
            //server response
            obj_ServerResponse response = new obj_ServerResponse();
            int affectedRows            = 0;

            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            mdl_Item             item           = jsonSerializer.Deserialize <mdl_Item>(collection);
            var context = new ValidationContext(item);
            var results = new List <ValidationResult>();

            if (Validator.TryValidateObject(item, context, results, true))
            {
                gp_InventoryItems dbItem = db.gp_InventoryItems.Find(item.ItemId);
                if (dbItem == null)
                {
                    //item not found
                    response.MessageType = "warning";
                    response.Message     = "Item not found!";
                    response.ShowDialog  = true;
                }

                //validate existing vendor item number
                IQueryable <gp_InventoryItems> existingItems = db.gp_InventoryItems.Where(d => d.VNDITNUM == item.VendorItemNumber && d.ItemId != item.ItemId);
                if (existingItems.Count() > 0)
                {
                    response.MessageType = "warning";
                    response.Message     = "An item already has that vendor code, try again!";
                    response.ShowDialog  = true;

                    return(new JsonNetResult(response));
                }

                //only edit custom, unsynced items
                if (dbItem.CustomItem != true || dbItem.Synced == true)
                {
                    //item not found
                    response.MessageType = "warning";
                    response.Message     = "Can't edit this item!";
                    response.ShowDialog  = true;
                    return(new JsonNetResult(response));
                }


                gp_InventoryItems currentItem = db.gp_InventoryItems.AsNoTracking().Where(d => d.ItemId == item.ItemId).First();

                dbItem.VNDITNUM = item.VendorItemNumber;
                dbItem.VNDITDSC = item.VendorItemDescription;

                db.Entry(dbItem).State = EntityState.Modified;
                affectedRows           = db.SaveChanges();

                if (affectedRows > 0)
                {
                    response.MessageType = "success";
                    response.Message     = "Item updated successfully!";
                    response.ShowDialog  = true;
                }
                else
                {
                    response.MessageType = "warning";
                    response.Message     = "There was a problem updating this item!";
                    response.ShowDialog  = true;
                }
            }
            else
            {
                response.Errors = results.Select(d => new KeyValuePair <string, string>(d.MemberNames.First().ToString(), d.ErrorMessage));
            }

            return(new JsonNetResult(response));
        }
Example #6
0
        /// <summary>
        /// Get forecast items/summary
        /// </summary>
        /// <param name="id">Year</param>
        /// <returns></returns>
        public JsonNetResult GetForecastItems(int id)
        {
            obj_ServerResponse response = new obj_ServerResponse();

            tbl_Forecasts dbForecast = db.tbl_Forecasts.Find(id);

            if (dbForecast == null)
            {
                //item not found
                response.MessageType = "warning";
                response.Message     = "Forecast not found!";
                response.ShowDialog  = true;
            }
            mdl_Forecast model = new mdl_Forecast();

            model.ForecastId = id;
            model.Year       = dbForecast.Year;


            List <mdl_ForecastItems> data = db.AAA2018_GET_FORECAST_SUMMARY_DATA(id).Select(d => new mdl_ForecastItems()
            {
                CustomItem      = d.CustomItem,
                ItemDescription = d.ItemDescription,
                ItemId          = d.ItemId ?? 0,
                ItemNumber      = d.ItemNumber,
                ItemWeight      = d.ItemWeight,
                I = null,
                M = null,
                P = null,
                VendorItemDescription = d.VendorItemDescription,
                VendorItemNumber      = d.VendorItemNumber,
                Month          = d.Month,
                ForecastItemId = d.ForecastItemId,
                Original       = d.Original,
                Revised        = d.Revised
            }).ToList <mdl_ForecastItems>();

            //populate matrix data
            model.ForecastItems = new List <mdl_ForecastItems>();

            for (int i = 0; i < data.Count(); i++)
            {
                mdl_ForecastItems item = data[i];
                item.ForecastData = new List <mdl_ForecastItemData>();

                //get data for each month
                for (int m = 1; m <= 12; m++)
                {
                    mdl_ForecastItemData mdata = new mdl_ForecastItemData();
                    mdata.Month = m;
                    if (data[i].Month == m)
                    {
                        mdata.Revised  = data[i].Revised ?? 0;
                        mdata.Forecast = data[i].Original ?? 0;
                    }
                    else
                    {
                        mdata.Revised  = 0;
                        mdata.Forecast = 0;
                    }

                    item.ForecastData.Add(mdata);
                }
                model.ForecastItems.Add(item);
            }


            return(new JsonNetResult(model));
        }