public async Task <IResponse <ActionInRole> > AddAsync(ActionInRole model)
        {
            if (await _authUow.ActionInRoleRepo.AnyAsync(x => x.RoleId == model.RoleId && x.ActionId == model.ActionId))
            {
                return new Response <ActionInRole> {
                           Message = ServiceMessage.DuplicateRecord, IsSuccessful = false
                }
            }
            ;

            if (model.IsDefault)
            {
                var existActionInRole = await _authUow.ActionInRoleRepo.FirstOrDefaultAsync(conditions : x => x.RoleId == model.RoleId && x.IsDefault);

                if (existActionInRole.IsNotNull())
                {
                    existActionInRole.IsDefault = false;
                }
            }

            await _authUow.ActionInRoleRepo.AddAsync(model);

            var saveResult = await _authUow.ElkSaveChangesAsync();

            return(new Response <ActionInRole>
            {
                Result = model,
                Message = saveResult.Message,
                IsSuccessful = saveResult.IsSuccessful,
            });
        }
Exemplo n.º 2
0
        public virtual async Task <JsonResult> Add(ActionInRole model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { IsSuccessful = false, Message = ModelState.GetModelError() }));
            }
            var addRep = await _actionInRoleSrv.AddAsync(model);

            if (!addRep.IsSuccessful)
            {
                return(Json(addRep));
            }
            var getRep = _actionInRoleSrv.GetViaAction(model.ActionId).ToList();

            getRep.ForEach((x) =>
            {
                x.Role.ActionInRoles = null;
            });

            return(Json(new Response <string>
            {
                IsSuccessful = true,
                Result = ControllerExtension.RenderViewToString(this, "Partials/_ListViaAction", getRep)
            }));
        }