/// <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); }
/// <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); }