示例#1
0
        public async Task <ActionResult> CreateOrEdit(CreateOrUpdateUser input)
        {
            if (ModelState.IsValid)
            {
                UserListDto userDto;
                if (input.User.ID.HasValue)
                {
                    userDto = await Edit(input.User, input.RoleIds);
                }
                else
                {
                    userDto = await Create(input.User, input.RoleIds);
                }

                return(Json(new Result <UserListDto>()
                {
                    Status = Status.Success,
                    Message = "操作成功",
                    Data = userDto
                }));
            }
            else
            {
                IEnumerable <string> errors = ModelStateToArray();
                return(Json(new Result
                {
                    Status = Status.Failure,
                    Message = "[" + string.Join(",", errors) + "]"
                }));
            }
        }
示例#2
0
        public GenericResponse UpdateUser(CreateOrUpdateUser request)
        {
            string userId = ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst(ClaimTypes.NameIdentifier).Value.ToString();

            if (request.id != userId)
            {
                return(new GenericResponse(403, "Kullanıcı sadece kendi bilgilerini düzenleyebilir !"));
            }

            return(userRepo.CreateOrUpdateUser(request));
        }
        public GenericResponse CreateOrUpdateUser(CreateOrUpdateUser request)
        {
            try
            {
                User user = db.Users.Where(u => u.Id == request.id && u.IsDeleted != true).FirstOrDefault();

                if (user == null)
                {
                    User validateName = db.Users.Where(u => u.Name == request.name && u.IsDeleted != true).FirstOrDefault();// tokenı username bakarak ürettiğim için böyle bir kontrol var.
                    if (validateName != null)
                    {
                        return(new GenericResponse(1, "bu username ile kayıtlı bir kullanıcı sistemde zaten mevcut."));
                    }

                    user            = new User();
                    user.CreateDate = DateTime.Now;
                    user.IsDeleted  = false;
                    db.Users.Add(user);
                }

                user.Name  = request.name;
                user.Phone = request.phone;

                db.SaveChanges();
                UserDto respDto = new UserDto(user);

                GenericResponse response = new GenericResponse();
                response.entity = respDto;

                return(response);
            }
            catch (Exception ex)
            {
                ApiLog log = new ApiLog();

                log.Request    = request.ToString();
                log.MethodName = "CreateOrUpdateUser";
                log.Exception  = ex.ToString();
                log.UserId     = "";

                db.ApiLog.Add(log);
                db.SaveChanges();

                return(new GenericResponse(ex));
            }
        }
示例#4
0
 public GenericResponse NewUser(CreateOrUpdateUser request)
 {
     return(userRepo.CreateOrUpdateUser(request));
 }