public ActionResult Index(StoreProfileViewModel SPViewModel, string value)
        {
            StoreProfileManager SPManager = new StoreProfileManager();

            SPViewModel             = SPManager.SearchSingleStore(value);
            SPViewModel.HasSearched = true;
            SPViewModel.StoreList   = SPManager.SearchStores("ALL");
            return(View(SPViewModel));
        }
Esempio n. 2
0
 public List <StoreProfileViewModel> GetStoreList()
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         List <StoreProfileViewModel> spList = new List <StoreProfileViewModel>();
         for (int i = 0; i < db.Store_Profile.Count(); i++)
         {
             StoreProfileViewModel spViewModel = new StoreProfileViewModel();
             spViewModel.STORE_NO   = db.Store_Profile.ElementAt(i).STORE_NO.ToString();
             spViewModel.STORE_NAME = db.Store_Profile.ElementAt(i).STORE_NAME;
             spViewModel.LOCATION   = db.Store_Profile.ElementAt(i).LOCATION.ToString();
             spList.Add(spViewModel);
         }
         return(spList);
     }
 }
        // GET: StoreProfile
        public ActionResult Index(string id)
        {
            // Validate log in and user access
            UserAccessSession UASession = (UserAccessSession)Session["UserAccess"];

            if (UASession == null || !UASession.STP)
            {
                return(RedirectToAction("Login", "Account"));
            }
            // Set NavBar Links accordingly
            Session["CurrentPage"] = new CurrentPageSession("STP", "HOME", "LOG");

            // SearchItemSelected is assigned value at DisplaySearchResult
            StoreProfileManager   SPManager   = new StoreProfileManager();
            StoreProfileViewModel SPViewModel = new StoreProfileViewModel();

            if (id != null)
            {
                SPViewModel = SPManager.SearchSingleStore(id);
            }
            SPViewModel.StoreList = SPManager.SearchStores("ALL");
            return(View(SPViewModel));
        }
        public StoreProfileViewModel SearchSingleStore(string SearchItem)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Store_Profile SPRow;
                if (db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(SearchItem)).Any())
                {
                    SPRow = db.Store_Profile.Single(sp => sp.STORE_NO.ToString().Equals(SearchItem));
                }
                else
                {
                    return(null);
                }

                StoreProfileViewModel vm = new StoreProfileViewModel();
                vm.STORE_NO = SPRow.STORE_NO.ToString().Trim();

                if (SPRow.STORE_NAME != null)
                {
                    vm.STORE_NAME = SPRow.STORE_NAME.Trim();
                }

                if (SPRow.OWNERSHIP != null)
                {
                    vm.OWNERSHIP = SPRow.OWNERSHIP.ToString();
                }

                if (SPRow.BREAKFAST_PRICE_TIER != null)
                {
                    vm.BREAKFAST_PRICE_TIER = SPRow.BREAKFAST_PRICE_TIER.ToString();
                }

                if (SPRow.REGULAR_PRICE_TIER != null)
                {
                    vm.REGULAR_PRICE_TIER = SPRow.REGULAR_PRICE_TIER.ToString();
                }

                if (SPRow.DC_PRICE_TIER != null)
                {
                    vm.DC_PRICE_TIER = SPRow.DC_PRICE_TIER.ToString();
                }

                if (SPRow.MDS_PRICE_TIER != null)
                {
                    vm.MDS_PRICE_TIER = SPRow.MDS_PRICE_TIER.ToString();
                }

                if (SPRow.MCCAFE_LEVEL_2_PRICE_TIER != null)
                {
                    vm.MCCAFE_LEVEL_2_PRICE_TIER = SPRow.MCCAFE_LEVEL_2_PRICE_TIER.ToString();
                }

                if (SPRow.MCCAFE_LEVEL_3_PRICE_TIER != null)
                {
                    vm.MCCAFE_LEVEL_3_PRICE_TIER = SPRow.MCCAFE_LEVEL_3_PRICE_TIER.ToString();
                }

                if (SPRow.MCCAFE_BISTRO_PRICE_TIER != null)
                {
                    vm.MCCAFE_BISTRO_PRICE_TIER = SPRow.MCCAFE_BISTRO_PRICE_TIER.ToString();
                }

                if (SPRow.PROJECT_GOLD_PRICE_TIER != null)
                {
                    vm.PROJECT_GOLD_PRICE_TIER = SPRow.PROJECT_GOLD_PRICE_TIER.ToString();
                }

                if (SPRow.PROFIT_CENTER != null)
                {
                    vm.PROFIT_CENTER = SPRow.PROFIT_CENTER.ToString();
                }

                if (SPRow.REGION != null)
                {
                    vm.REGION = SPRow.REGION.Trim();
                }

                if (SPRow.PROVINCE != null)
                {
                    vm.PROVINCE = SPRow.PROVINCE.Trim();
                }

                if (SPRow.LOCATION != null)
                {
                    vm.LOCATION = SPRow.LOCATION.ToString();
                }

                if (SPRow.ADDRESS != null)
                {
                    vm.ADDRESS = SPRow.ADDRESS.Trim();
                }

                if (SPRow.CITY != null)
                {
                    vm.CITY = SPRow.CITY.Trim();
                }

                if (SPRow.FRESH_OR_FROZEN != null)
                {
                    vm.FRESH_OR_FROZEN = SPRow.FRESH_OR_FROZEN.Trim();
                }

                if (SPRow.PAPER_OR_PLASTIC != null)
                {
                    vm.PAPER_OR_PLASTIC = SPRow.PAPER_OR_PLASTIC.Trim();
                }

                if (SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX != null)
                {
                    vm.SOFT_SERVE_OR_VANILLA_POWDER_MIX = SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX.Trim();
                }

                if (SPRow.SIMPLOT_OR_MCCAIN != null)
                {
                    vm.SIMPLOT_OR_MCCAIN = SPRow.SIMPLOT_OR_MCCAIN.Trim();
                }

                if (SPRow.MCCORMICK_OR_GSF != null)
                {
                    vm.MCCORMICK_OR_GSF = SPRow.MCCORMICK_OR_GSF.Trim();
                }

                if (SPRow.FRESHB_OR_FROZENB != null)
                {
                    vm.FRESHB_OR_FROZENB = SPRow.FRESHB_OR_FROZENB;
                }

                if (SPRow.BET != null)
                {
                    vm.BET = GetBusinessExtension(SPRow.BET, vm.BusinessExtList);
                }

                if (SPRow.Group != null)
                {
                    vm.Group = (int)SPRow.Group;
                }

                else
                {
                    vm.Group = 0;
                }
                return(vm);
            }
        }
        /*
         * Combined Create and Update Store profile method.
         * Creates a Store_Profile instance (which will be a new table row)
         * and instantiates each SPViewModel property to the respective property of the former.
         * Also checks if the given Store profile number is already in the table,
         * if true, the method performs an update, otherwise, creation.
         *
         * Returns true if the operation is successful.
         * */
        public bool UpdateStore(StoreProfileViewModel SPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Store_Profile SPRow;
                bool          isUpdating = false;
                if (db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(SPViewModel.STORE_NO)).Any())
                {
                    SPRow      = db.Store_Profile.Single(o => o.STORE_NO.ToString().Equals(SPViewModel.STORE_NO));
                    isUpdating = true;
                }
                else
                {
                    SPRow = new Store_Profile();
                }

                if (SPViewModel.STORE_NO != null && !SPViewModel.STORE_NO.Equals(""))
                {
                    SPRow.STORE_NO = int.Parse(SPViewModel.STORE_NO);
                }
                else
                {
                    return(false);
                }

                if (SPViewModel.STORE_NAME != null && !SPViewModel.STORE_NAME.Equals(""))
                {
                    SPRow.STORE_NAME = SPViewModel.STORE_NAME;
                }
                else
                {
                    return(false);
                }

                if (SPViewModel.OWNERSHIP != null)
                {
                    SPRow.OWNERSHIP = int.Parse(SPViewModel.OWNERSHIP);
                }
                if (SPViewModel.BREAKFAST_PRICE_TIER != null)
                {
                    SPRow.BREAKFAST_PRICE_TIER = int.Parse(SPViewModel.BREAKFAST_PRICE_TIER);
                }
                if (SPViewModel.REGULAR_PRICE_TIER != null)
                {
                    SPRow.REGULAR_PRICE_TIER = int.Parse(SPViewModel.REGULAR_PRICE_TIER);
                }
                if (SPViewModel.DC_PRICE_TIER != null)
                {
                    SPRow.DC_PRICE_TIER = int.Parse(SPViewModel.DC_PRICE_TIER);
                }
                if (SPViewModel.MDS_PRICE_TIER != null)
                {
                    SPRow.MDS_PRICE_TIER = int.Parse(SPViewModel.MDS_PRICE_TIER);
                }
                if (SPViewModel.MCCAFE_LEVEL_2_PRICE_TIER != null)
                {
                    SPRow.MCCAFE_LEVEL_2_PRICE_TIER = int.Parse(SPViewModel.MCCAFE_LEVEL_2_PRICE_TIER);
                }
                if (SPViewModel.MCCAFE_LEVEL_3_PRICE_TIER != null)
                {
                    SPRow.MCCAFE_LEVEL_3_PRICE_TIER = int.Parse(SPViewModel.MCCAFE_LEVEL_3_PRICE_TIER);
                }
                if (SPViewModel.MCCAFE_BISTRO_PRICE_TIER != null)
                {
                    SPRow.MCCAFE_BISTRO_PRICE_TIER = int.Parse(SPViewModel.MCCAFE_BISTRO_PRICE_TIER);
                }
                if (SPViewModel.PROJECT_GOLD_PRICE_TIER != null)
                {
                    SPRow.PROJECT_GOLD_PRICE_TIER = int.Parse(SPViewModel.PROJECT_GOLD_PRICE_TIER);
                }
                if (SPViewModel.BusinessExtList != null)
                {
                    SPRow.BET = SetBusinessExtention(SPViewModel.BET, SPViewModel.BusinessExtList);
                }
                if (SPViewModel.PROFIT_CENTER != null)
                {
                    SPRow.PROFIT_CENTER = int.Parse(SPViewModel.PROFIT_CENTER);
                }
                if (SPViewModel.REGION != null)
                {
                    SPRow.REGION = SPViewModel.REGION;
                }
                if (SPViewModel.PROVINCE != null)
                {
                    SPRow.PROVINCE = SPViewModel.PROVINCE;
                }
                if (SPViewModel.LOCATION != null && !SPViewModel.LOCATION.Equals(""))
                {
                    SPRow.LOCATION = int.Parse(SPViewModel.LOCATION);
                }
                if (SPViewModel.ADDRESS != null)
                {
                    SPRow.ADDRESS = SPViewModel.ADDRESS;
                }
                if (SPViewModel.CITY != null)
                {
                    SPRow.CITY = SPViewModel.CITY;
                }
                if (SPViewModel.FRESH_OR_FROZEN != null)
                {
                    SPRow.FRESH_OR_FROZEN = SPViewModel.FRESH_OR_FROZEN;
                }
                if (SPViewModel.PAPER_OR_PLASTIC != null)
                {
                    SPRow.PAPER_OR_PLASTIC = SPViewModel.PAPER_OR_PLASTIC;
                }
                if (SPViewModel.SOFT_SERVE_OR_VANILLA_POWDER_MIX != null)
                {
                    SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX = SPViewModel.SOFT_SERVE_OR_VANILLA_POWDER_MIX;
                }
                if (SPViewModel.SIMPLOT_OR_MCCAIN != null)
                {
                    SPRow.SIMPLOT_OR_MCCAIN = SPViewModel.SIMPLOT_OR_MCCAIN;
                }
                if (SPViewModel.MCCORMICK_OR_GSF != null)
                {
                    SPRow.MCCORMICK_OR_GSF = SPViewModel.MCCORMICK_OR_GSF;
                }
                if (SPViewModel.FRESHB_OR_FROZENB != null)
                {
                    SPRow.FRESHB_OR_FROZENB = SPViewModel.FRESHB_OR_FROZENB;
                }
                SPRow.STATUS = "A";
                // Group
                if (db.ITMGRPs.Where(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Any())
                {
                    if (SPViewModel.Group == 0)
                    {
                        int val = db.ITMGRPs.FirstOrDefault(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Id;
                        ItemGroupManager.DeleteItem(val);
                    }
                    else
                    {
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Item_Code  = int.Parse(SPViewModel.STORE_NO);
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Item_Name  = SPViewModel.STORE_NAME;
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Group_Id   = SPViewModel.Group;
                        db.ITMGRPs.Single(o => o.Item_Code.ToString().Equals(SPViewModel.STORE_NO)).Group_Name = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == SPViewModel.Group).Group_Name;
                    }
                }
                else
                {
                    if (SPViewModel.Group != 0)
                    {
                        ItemGroupViewModel IGRow = new ItemGroupViewModel();
                        IGRow.GroupName = db.ITMGRPs.FirstOrDefault(o => o.Group_Id == SPViewModel.Group).Group_Name;
                        IGRow.GroupId   = SPViewModel.Group;
                        IGRow.ItemCode  = int.Parse(SPViewModel.STORE_NO);
                        IGRow.ItemName  = SPViewModel.STORE_NAME;
                        IGRow.ItemType  = 3;
                        IGRow.GroupType = 3;
                        ItemGroupManager.UpdateGroup(IGRow);
                    }
                }
                SPRow.Group = SPViewModel.Group;
                try
                {
                    // Check if STORE_NO already exists in the database, perform an update if true
                    if (isUpdating)
                    {
                        SPRow.STATUS = "E";
                    }
                    else
                    {
                        db.Store_Profile.Add(SPRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
        /*
         * Deletes a row in the `Store Profile` table
         *
         * Returns true if operation is successful.
         */
        public bool DeleteStore(StoreProfileViewModel SPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Store_Profile SPRow;
                if (db.Store_Profile.Where(o => o.STORE_NO.ToString().Equals(SPViewModel.STORE_NO)).Any())
                {
                    SPRow = db.Store_Profile.Single(sp => sp.STORE_NO.ToString().Equals(SPViewModel.STORE_NO));

                    // Remove from Menu Items
                    //      Remove from `Store`
                    if (db.CSHMIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <CSHMIMP0> MIRow = db.CSHMIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    //      Remove from `Except_Store`
                    if (db.CSHMIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <CSHMIMP0> MIRow = db.CSHMIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    // Remove from Raw Items
                    //      Remove from `Store`
                    if (db.INVRIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVRIMP0> MIRow = db.INVRIMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    //      Remove from `Except_Store`
                    if (db.INVRIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVRIMP0> MIRow = db.INVRIMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    // Remove from Vendors
                    //      Remove from `Store`
                    if (db.INVVEMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVVEMP0> MIRow = db.INVVEMP0.Where(o => o.Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    //      Remove from `Except_Store`
                    if (db.INVVEMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).Any())
                    {
                        List <INVVEMP0> MIRow = db.INVVEMP0.Where(o => o.Except_Store.Equals(SPViewModel.STORE_NO)).ToList();
                        foreach (var v in MIRow)
                        {
                            v.Store = null;
                        }
                    }
                    // Delete Group
                    if (db.ITMGRPs.Where(o => o.Item_Code == SPRow.STORE_NO).Any())
                    {
                        db.ITMGRPs.RemoveRange(db.ITMGRPs.Where(o => o.Item_Code == SPRow.STORE_NO));
                    }
                }
                else
                {
                    return(false);
                }

                try
                {
                    db.Store_Profile.Remove(SPRow);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }
        public ActionResult UpdateDelete(StoreProfileViewModel SPViewModel, string command)
        {
            StoreProfileManager SPManager = new StoreProfileManager();
            UserSession         user      = (UserSession)Session["User"];
            string PageAction             = "";
            bool   result = false;

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files["FileUploaded"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    ReportViewModel report = StoreProfileManager.ImportExcel(file.InputStream, user.Username);
                    PageAction = "Import";
                    result     = report.Result;
                    if (!result)
                    {
                        if (report.ErrorLevel == 2)
                        {
                            PageAction = report.Message + ": Import partially";
                        }
                        else
                        {
                            PageAction = report.Message + ": Import";
                        }
                    }
                    else
                    {
                        PageAction = report.Message + ": Import";
                    }
                }
            }
            if (command == "Save")
            {
                result     = SPManager.UpdateStore(SPViewModel);
                PageAction = "Create";
                if (SPViewModel.HasSearched)
                {
                    PageAction = "Update";
                }
            }
            else if (command == "Delete")
            {
                result     = SPManager.DeleteStore(SPViewModel);
                PageAction = "Delete";
            }
            if (result)
            {
                TempData["SuccessMessage"] = PageAction + " successful";
                new AuditLogManager().Audit(user.Username, DateTime.Now, "Store Profile", PageAction, SPViewModel.STORE_NO, SPViewModel.STORE_NAME);
                if (!PageAction.Equals("Delete"))
                {
                    return(RedirectToAction("Index", new { id = SPViewModel.STORE_NO }));
                }
            }
            else
            {
                TempData["ErrorMessage"] = PageAction + " failed";
            }
            return(RedirectToAction("Index"));
        }