public IActionResult Index(int Id = 0)
        {
            var menuItem = new MenuItem_VM();

            ViewBag.Currency     = new SelectList(_currencyRepository.GetByClientId(clientId), "Id", "Currency");
            ViewBag.ConceptsList = new SelectList(conceptsList, "Id", "ConceptName");
            if (Id > 0)
            {
                menuItem = _menuItemRepository.Get(Id, this.loginUserId, isAdmin);
                if (menuItem == null)
                {
                    return(RedirectToAction("List", "MenuItem"));
                }
                else
                {
                    categoryList       = _categoryRepository.GetList(this.loginUserId, isAdmin).Where(p => p.CategoryConcepts.Any(c => menuItem.ConceptIds.Any(c2 => c2 == c.Id))).ToList();
                    itemTagList        = _itemTagRepository.GetList(this.loginUserId, isAdmin).Where(p => p.ItemTagsConcepts.Any(c => menuItem.ConceptIds.Any(c2 => c2 == c.Id))).ToList();
                    ViewBag.Categories = new SelectList(categoryList, "Id", "Name");
                    ViewBag.ItemTags   = new SelectList(itemTagList, "Id", "Name");
                    return(View(menuItem));
                }
            }
            else
            {
                if (conceptsList.Any())
                {
                    if (SelectedConceptId > 0)
                    {
                        menuItem.ConceptIds = new List <int>()
                        {
                            conceptsList.Where(x => x.Id == SelectedConceptId).Select(x => x.Id).FirstOrDefault()
                        };
                        categoryList = _categoryRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.CategoryConcepts.Any(x => x.Id == SelectedConceptId)).ToList();
                        itemTagList  = _itemTagRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.ItemTagsConcepts.Any(x => x.Id == SelectedConceptId)).ToList();
                    }
                    else
                    {
                        menuItem.ConceptIds = new List <int>()
                        {
                            conceptsList[0].Id
                        };
                        categoryList = _categoryRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.CategoryConcepts.Any(x => x.Id == conceptsList[0].Id)).ToList();
                        itemTagList  = _itemTagRepository.GetList(this.loginUserId, isAdmin).Where(x => x.Status && x.ItemTagsConcepts.Any(x => x.Id == conceptsList[0].Id)).ToList();
                    }
                }

                ViewBag.Categories = new SelectList(categoryList, "Id", "Name");
                ViewBag.ItemTags   = new SelectList(itemTagList, "Id", "Name");

                ViewData["Title"] = "Add";
                return(View(menuItem));
            }
        }
        public async Task <IActionResult> SaveAsync(MenuItem_VM menuItem_VM)
        {
            if (menuItem_VM != null)
            {
                if (menuItem_VM.ThumbnailImage != null && menuItem_VM.ThumbnailImage.Length > 0)
                {
                    menuItem_VM.ThumbnailImageName = await Helper.FileUploadAsync(path, menuItem_VM.ThumbnailImage);
                }

                if (menuItem_VM.LargeImage != null && menuItem_VM.LargeImage.Length > 0)
                {
                    menuItem_VM.LargeImageName = await Helper.FileUploadAsync(path, menuItem_VM.LargeImage);
                }

                if (menuItem_VM.OverLayImage != null && menuItem_VM.OverLayImage.Length > 0)
                {
                    menuItem_VM.OverLayImageName = await Helper.FileUploadAsync(path, menuItem_VM.OverLayImage);
                }

                if (menuItem_VM.Id > 0)
                {
                    if (_menuItemRepository.Update(menuItem_VM, this.loginUserId) > 0)
                    {
                        TempData["Status"]  = Helper.success_code;
                        TempData["Message"] = Message.menuItemUpdated;
                    }
                    else
                    {
                        TempData["Message"] = Message.menuItemUpdatedError;
                    }
                }
                else
                {
                    if (_menuItemRepository.Add(menuItem_VM, this.loginUserId) > 0)
                    {
                        TempData["Status"]  = Helper.success_code;
                        TempData["Message"] = Message.menuItemAdded;
                    }
                    else
                    {
                        TempData["Message"] = Message.menuItemAddedError;
                    }
                }
            }
            return(RedirectToAction("List", "MenuItem"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Function for update menu-item
        /// </summary>
        /// <param name="menuItem_VM"></param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public int Update(MenuItem_VM menuItem_VM, int loginUserId)
        {
            var ret = 1;

            using (var dbcxtransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var menuItem = _context.Emenu_MenuItems.Where(x => x.Id == menuItem_VM.Id && x.IsDeleted == false).FirstOrDefault();
                    if (menuItem != null)
                    {
                        menuItem.PLU                = menuItem_VM.PLU;
                        menuItem.Name               = menuItem_VM.Name;
                        menuItem.CategoryId         = menuItem_VM.CategoryId;
                        menuItem.CurrencyId         = menuItem_VM.CurrencyId;
                        menuItem.Price              = menuItem_VM.Price.Value;
                        menuItem.Status             = menuItem_VM.Status;
                        menuItem.DetailsEN          = menuItem_VM.DetailsEN;
                        menuItem.DetailsAR          = menuItem_VM.DetailsAR;
                        menuItem.ThumbnailImageName = menuItem_VM.ThumbnailImageName;
                        menuItem.LargeImageName     = menuItem_VM.LargeImageName;
                        menuItem.LargeDetailsEN     = menuItem_VM.LargeDetailsEN;
                        menuItem.LargeDetailsAR     = menuItem_VM.LargeDetailsAR;
                        menuItem.OverLayImageName   = menuItem_VM.OverLayImageName;
                        menuItem.OverlayDetailsEN   = menuItem_VM.OverlayDetailsEN;
                        menuItem.OverlayDetailsAR   = menuItem_VM.OverlayDetailsAR;
                        menuItem.ModifiedOn         = DateTime.Now;
                        menuItem.ModifiedBy         = loginUserId;
                        menuItem.CommentsEN         = menuItem_VM.CommentsEN;
                        menuItem.CommentsAR         = menuItem_VM.CommentsAR;
                        menuItem.LabelEN            = menuItem_VM.LabelEN;
                        menuItem.LabelAR            = menuItem_VM.LabelAR;
                        _context.SaveChanges();

                        // Delete old MenuItemTags
                        var oldMenuItemTag = _context.Emenu_MenuItemTags.Where(x => x.EMenuItemId == menuItem_VM.Id).ToList();
                        if (oldMenuItemTag.Any())
                        {
                            _context.Emenu_MenuItemTags.RemoveRange(oldMenuItemTag);
                            _context.SaveChanges();
                        }

                        // Add new MenuItemTags
                        var menuItemTags = new List <Emenu_MenuItemTags>();
                        foreach (var itemTagId in menuItem_VM.ItemTagsId)
                        {
                            var menuItemTag = new Emenu_MenuItemTags()
                            {
                                EMenuItemId = menuItem.Id,
                                ItemTagId   = itemTagId,
                            };
                            menuItemTags.Add(menuItemTag);
                        }
                        _context.Emenu_MenuItemTags.AddRange(menuItemTags);
                        _context.SaveChanges();


                        //Remove old concept
                        var oldMenuItemConcepts = _context.Emenu_MenuItemsConcepts.Where(x => x.MenuItemId == menuItem_VM.Id).ToList();
                        if (oldMenuItemConcepts.Any())
                        {
                            _context.Emenu_MenuItemsConcepts.RemoveRange(oldMenuItemConcepts);
                            _context.SaveChanges();
                        }

                        //Add new concept
                        var menuItemConcepts = new List <Emenu_MenuItemsConcepts>();
                        foreach (var conceptId in menuItem_VM.ConceptIds)
                        {
                            var menuItemConcept = new Emenu_MenuItemsConcepts();
                            menuItemConcept.MenuItemId = menuItem.Id;
                            menuItemConcept.ConceptId  = conceptId;
                            menuItemConcepts.Add(menuItemConcept);
                        }

                        _context.Emenu_MenuItemsConcepts.AddRange(menuItemConcepts);
                        _context.SaveChanges();

                        dbcxtransaction.Commit();
                    }
                    else
                    {
                        ret = 0;
                    }
                }
                catch (Exception ex)
                {
                    dbcxtransaction.Rollback();
                    ret = 0;
                }
            }
            return(ret);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Funtion for add menu item
        /// </summary>
        /// <param name="menuItem_VM"></param>
        /// <param name="loginUserId"></param>
        /// <returns></returns>
        public int Add(MenuItem_VM menuItem_VM, int loginUserId)
        {
            var ret = 1;

            using (var dbcxtransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var menuItem = new Emenu_MenuItems();
                    menuItem.PLU                = menuItem_VM.PLU;
                    menuItem.Name               = menuItem_VM.Name;
                    menuItem.CategoryId         = menuItem_VM.CategoryId;
                    menuItem.CurrencyId         = menuItem_VM.CurrencyId;
                    menuItem.Price              = menuItem_VM.Price.Value;
                    menuItem.Status             = menuItem_VM.Status;
                    menuItem.DetailsEN          = menuItem_VM.DetailsEN;
                    menuItem.DetailsAR          = menuItem_VM.DetailsAR;
                    menuItem.ThumbnailImageName = menuItem_VM.ThumbnailImageName;
                    menuItem.LargeImageName     = menuItem_VM.LargeImageName;
                    menuItem.LargeDetailsEN     = menuItem_VM.LargeDetailsEN;
                    menuItem.LargeDetailsAR     = menuItem_VM.LargeDetailsAR;
                    menuItem.OverLayImageName   = menuItem_VM.OverLayImageName;
                    menuItem.OverlayDetailsEN   = menuItem_VM.OverlayDetailsEN;
                    menuItem.OverlayDetailsAR   = menuItem_VM.OverlayDetailsAR;
                    menuItem.CreatedOn          = DateTime.Now;
                    menuItem.CreatedBy          = loginUserId;
                    menuItem.CommentsEN         = menuItem_VM.CommentsEN;
                    menuItem.CommentsAR         = menuItem_VM.CommentsAR;
                    menuItem.LabelEN            = menuItem_VM.LabelEN;
                    menuItem.LabelAR            = menuItem_VM.LabelAR;

                    _context.Emenu_MenuItems.Add(menuItem);
                    _context.SaveChanges();

                    var menuItemTags = new List <Emenu_MenuItemTags>();
                    foreach (var itemTagId in menuItem_VM.ItemTagsId)
                    {
                        var menuItemTag = new Emenu_MenuItemTags()
                        {
                            EMenuItemId = menuItem.Id,
                            ItemTagId   = itemTagId,
                        };
                        menuItemTags.Add(menuItemTag);
                    }

                    _context.Emenu_MenuItemTags.AddRange(menuItemTags);
                    _context.SaveChanges();

                    var menuItemConcepts = new List <Emenu_MenuItemsConcepts>();
                    foreach (var conceptId in menuItem_VM.ConceptIds)
                    {
                        var menuItemConcept = new Emenu_MenuItemsConcepts();
                        menuItemConcept.MenuItemId = menuItem.Id;
                        menuItemConcept.ConceptId  = conceptId;
                        menuItemConcepts.Add(menuItemConcept);
                    }

                    _context.Emenu_MenuItemsConcepts.AddRange(menuItemConcepts);
                    _context.SaveChanges();

                    dbcxtransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbcxtransaction.Rollback();
                    ret = 0;
                }
            }
            return(ret);
        }