Example #1
0
        public void CreateUser_IfObjectIsInvalid_AssignResulObject()
        {
            BOUser objUser         = new BOUser();
            var    mockUserService = new Mock <IUserService>();

            mockUserService.Setup(us => us.IsValid(objUser)).Returns(false);
            mockUserService.SetupGet(x => x.Errors).Returns(new List <string>()
            {
                "Error"
            });

            UserCO userCO = new UserCO(mockUserService.Object);

            var resp = userCO.CreateUser(objUser);

            Assert.IsNotNull(resp);
        }
Example #2
0
        public ActionResult UserUpdate(Guid userGuid, [FromForm] UserCO request)
        {
            if (request == null)
            {
                throw new PetClinicAppointmentBadRequestException("You have not sent any data!");
            }

            if (userGuid == default(Guid))
            {
                throw new PetClinicAppointmentBadRequestException("Submit valid user information!");
            }

            var kullanici = _userService.GetByGuid(userGuid);

            if (kullanici == null)
            {
                throw new PetClinicAppointmentNotFoundException("User not found!");
            }

            if (string.IsNullOrEmpty(request.Name))
            {
                throw new PetClinicAppointmentBadRequestException("Name is not null!");
            }

            if (string.IsNullOrEmpty(request.Surname))
            {
                throw new PetClinicAppointmentBadRequestException("Surname is not null!");
            }

            if (string.IsNullOrEmpty(request.Email))
            {
                throw new PetClinicAppointmentBadRequestException("Email is not null!");
            }

            var getKullanici = _userService.GetByKullaniciAdi(request.Email);


            if (getKullanici != null && kullanici.Email != getKullanici.Email)
            {
                throw new PetClinicAppointmentBadRequestException("Such a email already exists!");
            }

            var sonuc = new ResultDTO();

            kullanici.Name        = request.Name;
            kullanici.Surname     = request.Surname;
            kullanici.Email       = request.Email;
            kullanici.DogumTarihi = request.DogumTarihi;
            kullanici.KimlikNo    = request.KimlikNo;
            kullanici.DogumYeri   = request.DogumYeri;

            if (!string.IsNullOrEmpty(request.Password))
            {
                kullanici.TuzlamaDegeri = _userService.GetTuzlamaDegeri();

                kullanici.Password = _userService.Sifrele(request.Password, kullanici.TuzlamaDegeri);
            }

            var durum = _userService.Update(kullanici);

            if (durum < 1)
            {
                throw new PetClinicAppointmentBadRequestException("The user could not be updated!");
            }

            sonuc.Status = EDurum.SUCCESS;
            sonuc.Message.Add(new MessageDTO()
            {
                Code        = HttpStatusCode.OK,
                Status      = EDurum.SUCCESS,
                Description = "The user has been successfully updated."
            });
            sonuc.Data = new { user = new { kullanici.Guid } };
            return(Ok(sonuc));
        }