Exemple #1
0
        public async Task <JsonResult> SaveUserRole([FromBody] UserRoleModel model)
        {
            try
            {
                var userrole = new apec_khktdocs_userrole
                {
                    id           = model.id,
                    username     = model.username,
                    isadmin      = model.isadmin,
                    isapprove    = model.isapprove,
                    isaccess     = model.isaccess,
                    isdelete     = model.isdelete,
                    issuperadmin = 0
                };
                var result = await _userRoleService.SaveUserRole(userrole);

                if (result != -1)
                {
                    return(Json(new { status = "success", message = "success" }));
                }
                return(Json(new { status = "fail", message = "Không thêm mới cho user đã có quyền" }));
            }
            catch (System.Exception)
            {
                return(Json(new { status = "fail", message = "fail" }));
            }
        }
Exemple #2
0
        public async Task <int> SaveUserRole(apec_khktdocs_userrole role)
        {
            try
            {
                if (role.id != 0)
                {
                    var entity = await _userRoleRepository.GetByIdAsync(role.id).ConfigureAwait(false);

                    entity.isadmin   = role.isadmin;
                    entity.isapprove = role.isapprove;
                    entity.isdelete  = role.isdelete;
                    entity.username  = role.username;
                    entity.isaccess  = role.isaccess;

                    await _userRoleRepository.UpdateAsync(entity).ConfigureAwait(false);

                    return(role.id);
                }
                else
                {
                    var isexists = await GetUserRoleByUserName(role.username).ConfigureAwait(false);

                    if (isexists == null)
                    {
                        var result = await _userRoleRepository.SaveUserRole(role).ConfigureAwait(false);

                        return(result);
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
        }