public static ReportViewModel ImportExcel(Stream file, string user)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                ReportViewModel error = new ReportViewModel();
                XLWorkbook      workBook;
                try
                {
                    workBook = new XLWorkbook(file);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    error.Result     = false;
                    error.Message    = "File format not supported";
                    error.ErrorLevel = 3;
                    return(error);
                }
                IXLWorksheet workSheet     = workBook.Worksheet(1);
                var          MIMRowList    = new List <CSHMIMP0>();
                bool         IsFirstRow    = true;
                int          succesfulRows = 0;
                int          blankCounter  = 0;
                IXLRow       FirstRow      = workSheet.Rows().ElementAt(0);
                if (FirstRow == null || FirstRow.CellCount() <= 0)
                {
                    error.Result     = false;
                    error.ErrorLevel = 3;
                    error.Message    = "File has incorrect or unsupported format";
                    return(error);
                }
                int index = 1;
                foreach (IXLRow row in workSheet.Rows())
                {
                    if (row == null)
                    {
                        break;
                    }

                    if (IsFirstRow)
                    {
                        FirstRow   = row;
                        IsFirstRow = false;
                    }
                    else
                    {
                        if (row.Cells() == null || row.CellCount() <= 0)
                        {
                            break;
                        }

                        Store_Profile SPRow      = new Store_Profile();
                        int           errorLevel = 0;
                        for (int i = 1; i < row.CellCount(); i++)
                        {
                            System.Diagnostics.Debug.WriteLine("Cell count: " + i);
                            System.Diagnostics.Debug.WriteLine("Cell header: " + FirstRow.Cell(i).Value.ToString().ToUpper());
                            System.Diagnostics.Debug.WriteLine("Cell data: " + row.Cell(i).Value.ToString());
                            System.Diagnostics.Debug.WriteLine("Row: " + index);

                            if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("STORE_NO") ||
                                FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STORE NUMBER") ||
                                FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STORE #"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.STORE_NO = int.Parse(row.Cell(i).Value.ToString());
                                }
                                else
                                {
                                    error.Message += "Store number [" + row.Cell(i).Value.ToString() + "] at {Row " + index + "} not in the correct format. | ";
                                    if (error.ErrorLevel != 3)
                                    {
                                        errorLevel = 2;
                                    }
                                    error.Result = false;
                                    break;
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("STORE_NAME") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("STORE NAME"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.STORE_NAME = row.Cell(i).Value.ToString();
                                }
                                else
                                {
                                    error.Result   = false;
                                    error.Message += "Store name [" + row.Cell(i).Value.ToString() + "]  at {Row " + index + "} not in the correct format. | ";
                                    if (error.ErrorLevel != 3)
                                    {
                                        errorLevel = 2;
                                    }
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("OWNERSHIP") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("OWNERSHIP"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.OWNERSHIP = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROFIT_CENTER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PROFIT CENTER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PROFIT_CENTER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("BREAKFAST_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("BREAKFAST PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.BREAKFAST_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("REGULAR_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("REGULAR PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.REGULAR_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("DC_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("DC PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.DC_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MDS_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MDS PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MDS_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCAFE_LEVEL2_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCAFE LEVEL 2 PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCAFE_LEVEL_2_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCAFE_LEVEL3_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCAFE LEVEL 3 PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCAFE_LEVEL_3_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCAFE_BISTRO_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCAFE BISTRO PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCAFE_BISTRO_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROJECT_GOLD_PRICE_TIER") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PROJECT GOLD PRICE TIER"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PROJECT_GOLD_PRICE_TIER = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("BET") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("BUSINESS EXTENSION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.BET = row.Cell(i).Value.ToString();
                                }
                            }


                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("REGION") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("REGION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.REGION = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PROVINCE") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PROVINCE"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PROVINCE = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("LOCATION") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("LOCATION"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.LOCATION = int.Parse(row.Cell(i).Value.ToString());
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("ADDRESS") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("ADDRESS"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.ADDRESS = row.Cell(i).Value.ToString();
                                }
                                ;
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("CITY") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("CITY"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.CITY = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("FRESH_OR_FROZEN") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("FRESH OR FROZEN"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.FRESH_OR_FROZEN = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("PAPER_OR_PLASTIC") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("PAPER OR PLASTIC"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.PAPER_OR_PLASTIC = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("SOFT_SERVE_OR_VANILLA_POWDER_MIX") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("SOFT SERVE OR VANILLA POWDER MIX"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("SIMPLOT_OR_MCCAIN") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("SIMPLOT OR MCCAIN"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.SIMPLOT_OR_MCCAIN = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("MCCORMICK_OR_GSF") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("MCCORMICK OR GSF"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.MCCORMICK_OR_GSF = row.Cell(i).Value.ToString();
                                }
                            }

                            else if (FirstRow.Cell(i).Value.ToString().ToUpper().Equals("FRESHB_OR_FROZENB") ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains("FRESH BUNS OR FROZEN BUNS"))
                            {
                                if (row.Cell(i).Value != null && !row.Cell(i).Value.ToString().Equals(""))
                                {
                                    SPRow.SOFT_SERVE_OR_VANILLA_POWDER_MIX = row.Cell(i).Value.ToString();
                                }
                            }
                            else if (FirstRow.Cell(i).Value == null ||
                                     FirstRow.Cell(i).Value.ToString().ToUpper().Contains(""))
                            {
                                blankCounter++;
                                if (blankCounter > 20)
                                {
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        if (SPRow.STORE_NO == 0 || SPRow.STORE_NAME == null)
                        {
                            error.Result   = false;
                            error.Message += "{Row " + index + "} has incorrect format | ";
                            errorLevel     = 2;
                            break;
                        }

                        if (db.Store_Profile.Where(o => o.STORE_NO == SPRow.STORE_NO).Any())
                        {
                            error.Result   = false;
                            error.Message += "Store profile [" + SPRow.STORE_NO + "] at {Row " + index + "} is already defined | ";
                            errorLevel     = 2;
                        }

                        if (SPRow.OWNERSHIP != null && !SPRow.OWNERSHIP.Equals("") && !db.OWNERSHIPs.Where(o => o.Id == SPRow.OWNERSHIP).Any())
                        {
                            error.Result   = false;
                            error.Message += "Ownership with Id [" + SPRow.OWNERSHIP + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (SPRow.PROFIT_CENTER != null && !SPRow.PROFIT_CENTER.Equals("") && !db.PROFIT_CEN.Where(o => o.Id == SPRow.PROFIT_CENTER).Any())
                        {
                            error.Result   = false;
                            error.Message += "Ownership with Id [" + SPRow.PROFIT_CENTER + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (SPRow.LOCATION != null && !SPRow.PROFIT_CENTER.Equals("") && !db.LOCATIONs.Where(o => o.Id == SPRow.LOCATION).Any())
                        {
                            error.Result   = false;
                            error.Message += "Location with Id [" + SPRow.LOCATION + "] at {Row " + index + "} not available | ";
                            errorLevel     = 2;
                        }

                        if (errorLevel >= 2)
                        {
                            error.Message += "{Row " + index + "} not inserted | ";
                        }

                        if (errorLevel < 2)
                        {
                            db.Store_Profile.Add(SPRow);
                            try
                            {
                                db.SaveChanges();
                                // Special case for logging import
                                succesfulRows++;
                                new AuditLogManager().Audit(user, DateTime.Now, "Store profile", "Import", SPRow.STORE_NO.ToString(), SPRow.STORE_NAME);
                                System.Diagnostics.Debug.WriteLine(SPRow.STORE_NO);
                            }
                            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);
                                error.Result   = false;
                                error.Message += "{Row " + index + "} failed to insert. | \n";
                                errorLevel     = 2;
                            }
                        }
                        error.ErrorLevel = errorLevel;
                        index++;
                    }
                }
                if (succesfulRows <= 0)
                {
                    error.Result     = false;
                    error.Message   += "No rows imported | ";
                    error.ErrorLevel = 3;
                }
                else if (succesfulRows >= index)
                {
                    error.ErrorLevel = 0;
                    error.Result     = true;
                }
                error.Message += "Imported " + index + " rows. ";
                return(error);
            }
        }
Esempio n. 2
0
        public List <CSHMIMP0> GetMenutems(string Store_No, DateTime DateFrom, DateTime DateTo)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                Store_Profile   Store      = db.Store_Profile.Single(o => o.STORE_NO.ToString().Equals(Store_No));
                List <CSHMIMP0> sublist    = db.CSHMIMP0.Where(o => o.STATUS.Equals("A")).ToList();
                List <CSHMIMP0> list       = new List <CSHMIMP0>();
                List <CSHMIMP0> masterlist = new List <CSHMIMP0>();
                list.AddRange(sublist);
                sublist = db.CSHMIMP0.Where(o => o.STATUS.Equals("E")).ToList();
                list.AddRange(sublist);

                sublist = list.Where(o => (o.Store != null && o.Store.Equals(Store_No))).ToList();
                masterlist.AddRange(sublist);

                sublist = list.Where(o => (o.Store != null && o.Store.Equals("ALL"))).ToList();
                masterlist.AddRange(sublist);

                masterlist.RemoveAll(o => (o.Except_Store != null && o.Except_Store.Equals(Store_No)));

                masterlist.RemoveAll(o => o.MIMDAT < DateFrom);
                masterlist.RemoveAll(o => o.MIMDAT > DateTo);

                foreach (CSHMIMP0 mi in masterlist)
                {
                    int    tierIdToUse;
                    string tierToUse   = "";
                    int    tradingArea = (int)mi.Trading_Area;
                    if (tradingArea == 1)
                    {
                        tierIdToUse = (int)Store.BREAKFAST_PRICE_TIER;
                        tierToUse   = db.Breakfast_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 2)
                    {
                        tierIdToUse = (int)Store.REGULAR_PRICE_TIER;
                        tierToUse   = db.Regular_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 3)
                    {
                        tierIdToUse = (int)Store.MDS_PRICE_TIER;
                        tierToUse   = db.MDS_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 4)
                    {
                        tierIdToUse = (int)Store.DC_PRICE_TIER;
                        tierToUse   = db.Dessert_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 5)
                    {
                        tierIdToUse = (int)Store.PROJECT_GOLD_PRICE_TIER;
                        tierToUse   = db.Project_Gold_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 6)
                    {
                        tierIdToUse = (int)Store.MCCAFE_LEVEL_2_PRICE_TIER;
                        tierToUse   = db.McCafe_Level_2_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 7)
                    {
                        tierIdToUse = (int)Store.MCCAFE_LEVEL_3_PRICE_TIER;
                        tierToUse   = db.McCafe_Level_3_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    else if (tradingArea == 8)
                    {
                        tierIdToUse = (int)Store.MCCAFE_BISTRO_PRICE_TIER;
                        tierToUse   = db.McCafe_Bistro_Price_Tier.Single(o => o.Id == tierIdToUse).Price_Tier;
                    }
                    string    id = mi.MIMMIC + tierToUse;
                    MIM_Price MIMPriceRow;
                    if (db.MIM_Price.Where(o => o.Id.Equals(id)).Any())
                    {
                        MIMPriceRow = db.MIM_Price.Single(o => o.Id.Equals(id)); if (MIMPriceRow.MIMPRI != null && !MIMPriceRow.MIMPRI.Equals(""))
                        {
                            mi.MIMPRI = MIMPriceRow.MIMPRI; // Eat in
                        }
                        if (MIMPriceRow.MIMPRO != null && !MIMPriceRow.MIMPRO.Equals(""))
                        {
                            mi.MIMPRO = MIMPriceRow.MIMPRO; // Take out
                        }
                        if (MIMPriceRow.MIMPRG != null && !MIMPriceRow.MIMPRG.Equals(""))
                        {
                            mi.MIMPRG = MIMPriceRow.MIMPRG; // Other
                        }
                        if (MIMPriceRow.MIMNPA != null && !MIMPriceRow.MIMNPA.Equals(""))
                        {
                            mi.MIMNPA = MIMPriceRow.MIMNPA; // Non-product
                        }
                        // New
                        if (MIMPriceRow.MIMNPI != null && !MIMPriceRow.MIMNPI.Equals(""))
                        {
                            mi.MIMNPI = MIMPriceRow.MIMNPI; // Eat in new
                        }
                        if (MIMPriceRow.MIMNPO != null && !MIMPriceRow.MIMNPO.Equals(""))
                        {
                            mi.MIMNPO = MIMPriceRow.MIMNPO; // Take out new
                        }
                        if (MIMPriceRow.MIMNPD != null && !MIMPriceRow.MIMNPD.Equals(""))
                        {
                            mi.MIMNPD = MIMPriceRow.MIMNPD; // Other new
                        }
                        if (MIMPriceRow.MIMNNP != null && !MIMPriceRow.MIMNNP.Equals(""))
                        {
                            mi.MIMNNP = MIMPriceRow.MIMNNP; // Non-product new
                        }
                        // Effective date
                        if (MIMPriceRow.MIMPND != null && !MIMPriceRow.MIMPND.Equals(""))
                        {
                            mi.MIMPND = MIMPriceRow.MIMPND;
                        }
                    }
                }
                return(masterlist);
            }
        }
        /*
         * 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);
                }
            }
        }