Пример #1
0
        public ActionResult ManageLiquorCode(LiquorCodeModel liquorCodeModel)
        {
            if (ModelState.IsValid)
            {
                using (var ctx = new LicenseApplicationContext())
                {
                    LiquorCode liquorCode;
                    if (IsLiquorCodeDuplicate(liquorCodeModel.LiquorCodeDesc, liquorCodeModel.LiquorCodeID))
                    {
                        TempData["ErrorMessage"] = "Liquor Code already exists in the database.";
                        return(View(liquorCodeModel));
                    }

                    liquorCode = Mapper.Map <LiquorCode>(liquorCodeModel);
                    ctx.LiquorCodes.AddOrUpdate(liquorCode);
                    ctx.SaveChanges();
                }

                TempData["SuccessMessage"] = "Liquor Code saved successfully.";

                return(RedirectToAction("LiquorCode"));
            }
            else
            {
                return(View(liquorCodeModel));
            }
        }
Пример #2
0
        /// <summary>
        /// Get LiquorCode Data by ID
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult ManageLiquorCode(int?Id)
        {
            LiquorCodeModel liquorCodeModel = new LiquorCodeModel();

            liquorCodeModel.Active = true;
            if (Id != null && Id > 0)
            {
                using (var ctx = new LicenseApplicationContext())
                {
                    int liquorCodeID = Convert.ToInt32(Id);
                    var liquorCode   = ctx.LiquorCodes.Where(a => a.LiquorCodeID == liquorCodeID).FirstOrDefault();
                    liquorCodeModel = Mapper.Map <LiquorCodeModel>(liquorCode);
                }
            }

            return(View(liquorCodeModel));
        }