Ejemplo n.º 1
0
        public ActionResult AddParentMenu(int? ParentId, string WhichOpen, string MenuTextHtml, string ParentMenuName, string Type, int Priority)
        {
            string fileName = string.Empty;
            string tempImagePath = string.Empty;

            // if (IsValidSessions())
            //{
            if (TempData["ImagePath"] != null)
            {
                tempImagePath = TempData["ImagePath"].ToString();
                fileName = Path.GetFileName(tempImagePath);
            }

            ServiceGroup ServiceGroup = new ServiceGroup();
            int languageId = Convert.ToInt32(Session["Language"]);
            if (Type == "add")
            {

                ServiceGroup.Name = ParentMenuName;
                ServiceGroup.ParentID = ParentId;
                ServiceGroup.Priority = Priority;
                ServiceGroup.ImagePath = fileName;
                ServiceGroup.LanguageId = languageId;
                _RService.SaveServiceGroup(ServiceGroup);

                #region AddImage

                var path = $"~/Images/Product/Categories/{ServiceGroup.Id}";
                if (!Directory.Exists(Server.MapPath(path)))
                {
                    Directory.CreateDirectory(Server.MapPath(path));
                }

                if (TempData["ImagePath"] != null)
                {
                    System.IO.File.Move(tempImagePath, Server.MapPath(Path.Combine(path, fileName)));
                    var dir = tempImagePath.Substring(0, tempImagePath.LastIndexOf("\\"));
                    Directory.Delete(dir, true);
                }

                #endregion

                ViewBag.MenuList = _RService.ServiceGroups.Where(x => x.LanguageId == languageId).ToList();
                return PartialView("_ServiceGroupTreeview");
            }
            else
            {
                ServiceGroup = _RService.DetailsServiceGroup(Convert.ToInt32(ParentId));

                ServiceGroup.Name = ParentMenuName;
                if (fileName != string.Empty)
                    ServiceGroup.ImagePath = fileName;
                _RService.SaveServiceGroup(ServiceGroup);

                #region AddImage

                var path = $"~/Images/Product/Categories/{ServiceGroup.Id}";
                if (!Directory.Exists(Server.MapPath(path)))
                {
                    Directory.CreateDirectory(Server.MapPath(path));
                }
                else
                {
                    var files = Directory.GetFiles(Server.MapPath(path));
                    foreach (var file in files)
                    {
                        System.IO.File.Delete(file);
                    }
                }

                if (fileName != string.Empty)
                {
                    System.IO.File.Move(tempImagePath, Server.MapPath(Path.Combine(path, fileName)));
                    var dir = tempImagePath.Substring(0, tempImagePath.LastIndexOf("\\"));
                    Directory.Delete(dir, true);
                }

                #endregion

                //return Json(true);
                ViewBag.MenuList = _RService.ServiceGroups.Where(x => x.LanguageId == languageId).ToList();
                return PartialView("_ServiceGroupTreeview");
            }
            //}
            //else
            //    return JavaScript("window.location.href ='/Admin/Home/Login';");
        }
Ejemplo n.º 2
0
        public void SaveServiceGroup(ServiceGroup ServiceGroup)
        {
            try
            {
                 if (ServiceGroup.Id == 0)
                {
                    _RServiceGroup.Add(ServiceGroup);
                }
                else
                {
                    _uow.Entry(ServiceGroup).State = EntityState.Modified;
                }
            _uow.SaveChanges();
            }
            catch (Exception ex)
            {

            }
        }
Ejemplo n.º 3
0
 public void DeleteServiceGroup(ServiceGroup ServiceGroup)
 {
     _RServiceGroup.Remove(ServiceGroup);
     _uow.SaveChanges();
 }
Ejemplo n.º 4
0
 //written By Azizi 94_09_10
 public ServiceGroup GetTopmostLeavefromTree(bool firstTime, ServiceGroup node,int? languageId)
 {
     var group = new ServiceGroup();
     var childs = new List<ServiceGroup>();
     if (firstTime)
     {
         var roots = _RServiceGroup.Where(_ => _.ParentID == null && _.LanguageId == languageId);
         if (roots.Any())
         {
             var firstPrirityNode = roots.FirstOrDefault(_ => _.Priority == 1);
             if (firstPrirityNode != null)
             {
                 return GetTopmostLeavefromTree(false, firstPrirityNode,null);
             }
             return group;
         }
         return group;
     }
         childs = _RServiceGroup.Where(_ => _.ParentID == node.Id).ToList();
         if (childs.Any())
         {
             group = childs.FirstOrDefault(_ => _.Priority == 1);
             return GetTopmostLeavefromTree(false, group,null);
         }
         return node;
 }