public async Task <IActionResult> Create(SY_Role_Submit model, bool SaveAndCountinue = false)
        {
            model.Data_Tree = await _SY_MenuFunctionService.GetAllActive();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var obj = new SY_Role()
            {
                RoleName    = model.RoleName,
                Description = model.Description,
                Active      = model.Active,
                Id          = Guid.NewGuid().ToString()
            };

            if (!string.IsNullOrWhiteSpace(model.MenuFunctionIds))
            {
                var ks = model.MenuFunctionIds.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                model.MenuFunctions = new List <string>();
                foreach (var item in ks)
                {
                    model.MenuFunctions.Add(item);
                }

                foreach (var item in model.MenuFunctions)
                {
                    var t = new SY_Map_Role_Menu()
                    {
                        Id     = Guid.NewGuid().ToString(),
                        MenuId = item,
                        RoleId = obj.Id
                    };

                    await _SY_MenuFunctionService.CreateMap(t);
                }
            }

            //Thực hiện thêm mới
            var result = await _SY_RoleService.Create(obj);

            if (result.isSuccess)
            {
                if (SaveAndCountinue)
                {
                    TempData["Success"] = "Thêm mới thành công";
                    return(RedirectToAction("Create"));
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }
Exemple #2
0
        public async Task <MessageReport> Update(SY_Role model)
        {
            var query = new StringBuilder();

            query.AppendLine("{");
            query.AppendLine("'_id': { '$eq': '" + model.Id + "' }");
            query.AppendLine("}");

            return(await _SY_RoleRepository.Update(MongoHelper.ConvertQueryStringToDocument(query.ToString()), model));
        }
Exemple #3
0
        public async Task <SY_Role_Submit> GetCustomByModel(SY_Role model)
        {
            var obj = new SY_Role_Submit()
            {
                Id            = model.Id.ToString(),
                Active        = model.Active,
                Description   = model.Description,
                RoleName      = model.RoleName,
                MenuFunctions = new List <string>()
            };

            obj.MenuFunctions = (from n in _SY_Map_Role_MenuRepository.Table
                                 where n.RoleId == model.Id
                                 select n.MenuId).ToList();

            return(await Task.FromResult(obj));
        }
Exemple #4
0
 public async Task <MessageReport> Update(SY_Role model)
 {
     return(await _SY_RoleRepository.Update(model));
 }
Exemple #5
0
 public async Task <MessageReport> Create(SY_Role model)
 {
     return(await _SY_RoleRepository.Add(model));
 }