Example #1
0
        public ActionResult UpdateDelete(BreakfastPriceTierViewModel BPTViewModel, string command)
        {
            string PageAction = "";
            bool   result     = false;

            user = (UserSession)Session["User"];

            if (command == "Save")
            {
                BreakfastPriceTierManager BPTManager = new BreakfastPriceTierManager();
                result     = BPTManager.UpdateBreakfastPriceTier(BPTViewModel);
                PageAction = "UPDATE";
            }
            else if (command == "Delete")
            {
                BreakfastPriceTierManager BPTManager = new BreakfastPriceTierManager();
                result     = BPTManager.DeleteBreakfastPriceTier(BPTViewModel);
                PageAction = "DELETE";
            }
            if (result)
            {
                TempData["SuccessMessage"] = PageAction + " successful";
                new AuditLogManager().Audit(user.Username, DateTime.Now, "Breakfast Price Tier", PageAction, BPTViewModel.Id, BPTViewModel.Price_Tier);
            }
            else
            {
                TempData["ErrorMessage"] = PageAction + " failed";
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        // GET: BreakfastPriceTier
        public ActionResult Index()
        {
            // Validate log in and user access
            UserAccessSession UASession = (UserAccessSession)Session["UserAccess"];

            // TIP -> Price Tier
            // Refer to UserAccessSession
            if (UASession == null || !UASession.TIP)
            {
                return(RedirectToAction("Login", "Account"));
            }

            user = (UserSession)Session["User"];
            Session["CurrentPage"] = new CurrentPageSession("TIP_BRE", "HOME", "LOG");

            // Get all data stored in DB table
            BreakfastPriceTierManager   BPTManager   = new BreakfastPriceTierManager();
            BreakfastPriceTierViewModel BPTViewModel = new BreakfastPriceTierViewModel();

            BPTViewModel.BreakPTList = BPTManager.GetBPT();
            if (BPTViewModel.BreakPTList == null || BPTViewModel.BreakPTList.Count() == 0)
            {
                BPTViewModel.BreakPTList = new List <BreakfastPriceTierViewModel>();
            }
            // return View with ViewModel
            return(View(BPTViewModel));
        }
 public List <BreakfastPriceTierViewModel> GetBPT()
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         List <BreakfastPriceTierViewModel> BPTList = new List <BreakfastPriceTierViewModel>();
         foreach (Breakfast_Price_Tier bpt in db.Breakfast_Price_Tier)
         {
             BreakfastPriceTierViewModel BPTViewModel = new BreakfastPriceTierViewModel();
             BPTViewModel.Id         = (bpt.Id).ToString();
             BPTViewModel.Price_Tier = bpt.Price_Tier;
             // Add to List
             BPTList.Add(BPTViewModel);
         }
         return(BPTList);
     }
 }
 public bool UpdateBreakfastPriceTier(BreakfastPriceTierViewModel BPTViewModel)
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         Breakfast_Price_Tier bptRow = new Breakfast_Price_Tier();
         bptRow.Id         = int.Parse(BPTViewModel.Id);
         bptRow.Price_Tier = BPTViewModel.Price_Tier;
         try
         {
             if (db.Breakfast_Price_Tier.Where(o => o.Id.ToString().Equals(BPTViewModel.Id)).Any())
             {
                 var rowToRemove = db.Breakfast_Price_Tier.Single(o => o.Id.ToString().Equals(BPTViewModel.Id));
                 db.Breakfast_Price_Tier.Remove(rowToRemove);
                 db.Breakfast_Price_Tier.Add(bptRow);
             }
             else
             {
                 db.Breakfast_Price_Tier.Add(bptRow);
             }
             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);
         }
     }
 }