コード例 #1
0
        /// <summary>
        /// Function for add menu schedule
        /// </summary>
        /// <param name="menuSchedule_VM"></param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public int Add(MenuSchedule_VM menuSchedule_VM, int loginUserId)
        {
            string[] dates     = menuSchedule_VM.DateRange.Split('-');
            var      startDate = DateTime.Parse(dates[0]);
            var      endDate   = DateTime.Parse(dates[1]);

            var isOnSameDate = _context.Emenu_MenuSchedules.
                               Where(x => x.ConceptId == menuSchedule_VM.ConceptId &&
                                     x.StoreId == menuSchedule_VM.StoreId &&
                                     x.Status && !x.IsDeleted &&
                                     ((x.StartDate >= startDate && x.StartDate <= endDate) || (x.EndDate >= startDate && x.EndDate <= endDate))
                                     )
                               .FirstOrDefault();

            if (isOnSameDate == null)
            {
                var menuSchedule = new Emenu_MenuSchedules();
                menuSchedule.ConceptId  = menuSchedule_VM.ConceptId;
                menuSchedule.Code       = menuSchedule_VM.Code;
                menuSchedule.MenuId     = menuSchedule_VM.MenuId;
                menuSchedule.StartDate  = startDate;
                menuSchedule.EndDate    = endDate;
                menuSchedule.Status     = menuSchedule_VM.Status;
                menuSchedule.CreatedOn  = DateTime.Now;
                menuSchedule.CreatedBy  = loginUserId;
                menuSchedule.UniqueCode = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 12);
                menuSchedule.StoreId    = menuSchedule_VM.StoreId;
                _context.Emenu_MenuSchedules.Add(menuSchedule);
                return(_context.SaveChanges());
            }
            else
            {
                return(Helper.onsamedate_code);
            }
        }
コード例 #2
0
        public IActionResult Index(int Id = 0)
        {
            var menuSchedule = new MenuSchedule_VM();

            ViewBag.ConceptsList = new SelectList(conceptsList, "Id", "ConceptName");
            ViewBag.StoresList   = new SelectList(_storesRespository.GetStoresByUserId(this.loginUserId), "Id", "StoreName");
            if (Id > 0)
            {
                menuSchedule = _menuScheduleRepository.Get(Id, this.loginUserId, isAdmin);
                if (menuSchedule == null)
                {
                    return(RedirectToAction("List", "MenuSchedule"));
                }
                else
                {
                    menuSchedule.QRCode = Helper.GenerateQRCode(QRCodeUrl + Helper.Convert_StringvalueToHexvalue(menuSchedule.UniqueCode, System.Text.Encoding.Unicode));
                    menuList            = _menuRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.ConceptId == menuSchedule.ConceptId).ToList();
                    ViewBag.Menus       = new SelectList((from x in menuList
                                                          select new
                    {
                        Id = x.Id,
                        MenuCode = x.Name + "(" + x.Code + ")"
                    }).ToList(), "Id", "MenuCode");
                    ViewData["Title"] = "Edit";
                    return(View(menuSchedule));
                }
            }
            else
            {
                if (conceptsList.Any())
                {
                    if (SelectedConceptId > 0)
                    {
                        menuList = _menuRepository.GetList(this.loginUserId, isAdmin).Where(x => x.ConceptId == SelectedConceptId).ToList();
                        menuSchedule.ConceptId = SelectedConceptId;
                    }
                    else
                    {
                        menuList = _menuRepository.GetList(this.loginUserId, isAdmin).Where(x => x.ConceptId == conceptsList[0].Id).ToList();
                    }
                }

                ViewBag.Menus = new SelectList((from x in menuList
                                                select new
                {
                    Id = x.Id,
                    MenuCode = x.Name + "(" + x.Code + ")"
                }).ToList(), "Id", "MenuCode");

                ViewData["Title"] = "Add";
                return(View(menuSchedule));
            }
        }
コード例 #3
0
        /// <summary>
        /// Function for update menu schedule
        /// </summary>
        /// <param name="menuSchedule_VM"></param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public int Update(MenuSchedule_VM menuSchedule_VM, int loginUserId)
        {
            string[] dates     = menuSchedule_VM.DateRange.Split('-');
            var      startDate = DateTime.Parse(dates[0]);
            var      endDate   = DateTime.Parse(dates[1]);

            var isOnSameDate = _context.Emenu_MenuSchedules.
                               Where(x => x.ConceptId == menuSchedule_VM.ConceptId &&
                                     x.Id != menuSchedule_VM.Id &&
                                     x.StoreId == menuSchedule_VM.StoreId &&
                                     x.Status && !x.IsDeleted &&
                                     ((x.StartDate >= startDate && x.StartDate <= endDate) || (x.EndDate >= startDate && x.EndDate <= endDate))
                                     )
                               .FirstOrDefault();

            if (isOnSameDate == null)
            {
                var menuSchedule = _context.Emenu_MenuSchedules.Where(x => x.Id == menuSchedule_VM.Id && x.IsDeleted == false).FirstOrDefault();
                if (menuSchedule != null)
                {
                    menuSchedule.Code       = menuSchedule_VM.Code;
                    menuSchedule.ConceptId  = menuSchedule_VM.ConceptId;
                    menuSchedule.MenuId     = menuSchedule_VM.MenuId;
                    menuSchedule.Status     = menuSchedule_VM.Status;
                    menuSchedule.StartDate  = startDate;
                    menuSchedule.EndDate    = endDate;
                    menuSchedule.ModifiedBy = loginUserId;
                    menuSchedule.ModifiedOn = DateTime.Now;
                    menuSchedule.StoreId    = menuSchedule_VM.StoreId;
                    return(_context.SaveChanges());
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(Helper.onsamedate_code);
            }
        }
コード例 #4
0
 public IActionResult SaveAsync(MenuSchedule_VM menuSchedule_VM)
 {
     if (menuSchedule_VM != null)
     {
         if (menuSchedule_VM.Id > 0)
         {
             var result = _menuScheduleRepository.Update(menuSchedule_VM, this.loginUserId);
             if (result > 0)
             {
                 TempData["Status"]  = Helper.success_code;
                 TempData["Message"] = Message.menuScheduleUpdated;
             }
             else if (result == Helper.onsamedate_code)
             {
                 TempData["Message"] = Message.menuScheduleOnSameDateError;
             }
             else
             {
                 TempData["Message"] = Message.menuScheduleUpdatedError;
             }
         }
         else
         {
             var ret = _menuScheduleRepository.Add(menuSchedule_VM, this.loginUserId);
             if (ret > 0)
             {
                 TempData["Status"]  = Helper.success_code;
                 TempData["Message"] = Message.menuScheduleAdded;
             }
             else if (ret == Helper.onsamedate_code)
             {
                 TempData["Message"] = Message.menuScheduleOnSameDateError;
             }
             else
             {
                 TempData["Message"] = Message.menuScheduleAddedError;
             }
         }
     }
     return(RedirectToAction("List", "MenuSchedule"));
 }