示例#1
0
        public async Task <User> EditUser(EditProfileInputModel model)
        {
            User user = await this.dbContext.Users.FirstOrDefaultAsync(userDb => userDb.UserName == model.Username);

            bool existWithSameUsername = false;

            if (user.UserName != user.Email)
            {
                existWithSameUsername = await this.dbContext.Users.AnyAsync(userDb => userDb.UserName == model.Email);
            }

            if (!existWithSameUsername)
            {
                user.FirstName          = model.FirstName;
                user.LastName           = model.LastName;
                user.UserName           = model.Email;
                user.NormalizedUserName = model.Email.ToUpper();
                user.Email           = model.Email;
                user.NormalizedEmail = model.Email.ToUpper();
                user.PhoneNumber     = model.PhoneNumber;

                await this.dbContext.SaveChangesAsync();
            }

            return(user);
        }
示例#2
0
        public async Task UpdateAsync(string id, EditProfileInputModel input, string path)
        {
            var profile = this.profileRepository.All().FirstOrDefault(x => x.User.Id == id);

            if (profile != null)
            {
                this.ValidateCountryId(input.CountryId);

                var gender = this.GetGender(input.Gender);

                profile.FirstName = input.FirstName;
                profile.LastName  = input.LastName;
                profile.Gender    = gender;
                profile.BirthDate = input.BirthDate;
                profile.About     = input.About;
                profile.CountryId = input.CountryId;

                if (input.Image?.Length > 0)
                {
                    profile.ImageId = await this.imagesService.CreateAsync(input.Image, path);
                }

                this.profileRepository.Update(profile);
                await this.profileRepository.SaveChangesAsync();
            }
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [FromForm] EditProfileInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var userId    = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var profileId = this.profilesService.GetId(userId);

            if (profileId != id)
            {
                return(this.Unauthorized());
            }

            try
            {
                await this.profilesService.UpdateAsync(userId, input, $"{this.webHost.WebRootPath}/img/users");
            }
            catch (ArgumentException ae)
            {
                this.ModelState.AddModelError(string.Empty, ae.Message);

                return(this.BadRequest(this.ModelState));
            }

            return(this.Ok());
        }
示例#4
0
        public ActionResult UpdateProfile(EditProfileInputModel data)
        {
            string userID = HttpContext.Session.GetString(SessionKeyID);
            EditProfileInputModel dataProfile = new EditProfileInputModel();

            dataProfile          = data;
            dataProfile.EmailPIC = dataProfile.UserName;
            dataProfile.UserID   = Guid.Parse(HttpContext.Session.GetString(SessionKeyID).ToString());
            JsonConvert.SerializeObject(dataProfile);
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseAPI + "Profile/");
                //HTTP POST
                var postTask = client.PostAsJsonAsync <EditProfileInputModel>("EditProfile", dataProfile);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            ModelState.AddModelError(string.Empty, "Terjadi kesalahan server. Hubungi admin.");
            return(RedirectToAction("Update", "Profile"));
        }
示例#5
0
        public async Task UpdateAsync(int id, EditProfileInputModel input, string userId, List <string> imagePaths)
        {
            var images = new List <Image>();

            foreach (var imagePath in imagePaths)
            {
                var image = new Image()
                {
                    Url           = imagePath,
                    AddedByUserId = userId,
                    PetId         = input.Id,
                };
                images.Add(image);
            }

            var profiles = this.petsRepository.All().FirstOrDefault(x => x.Id == id);

            profiles.Name   = input.Name;
            profiles.Images = images;
            if (input.Description != null)
            {
                profiles.Description = input.Description;
            }

            await this.petsRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> EditProfile(EditProfileInputModel model)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var newUser = new ApplicationUser
            {
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Description = model.Description,
                Town        = model.Town,
                BirthDay    = model.BirthDay,
            };

            await this.newsFeedService.EditProfileAsync(newUser, user.Id);

            // string name = DateTime.UtcNow.ToString("G", CultureInfo.InvariantCulture);
            if (model.ProfilePicture != null)
            {
                string pictureUrlProfile = await this.cloudinary.UploadPictureAsync(model.ProfilePicture, model.ProfilePicture.FileName, FolderNameProfilePicture);

                await this.newsFeedService.CreateProfilePictureAsync(user.Id, pictureUrlProfile);
            }

            if (model.CoverPhoto != null)
            {
                string pictureUrlCover = await this.cloudinary.UploadPictureAsync(model.CoverPhoto, model.CoverPhoto.FileName, FolderNameCoverPicture);

                await this.newsFeedService.CreateCoverPictureAsync(user.Id, pictureUrlCover);
            }

            return(this.RedirectToAction(nameof(this.NewsFeedContent)));
        }
示例#7
0
        public async Task <IActionResult> Edit(EditProfileInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            if (input.Name == null)
            {
                input.Name = this.profilesService.GetName(input.Id);
            }

            var user = await this.userManager.GetUserAsync(this.User);

            if (input.Images != null)
            {
                var result = await CloudinaryExtentsion.UploadAsync(this.cloudinary, input.Images);

                await this.profilesService.UpdateAsync(input.Id, input, user.Id, result);
            }

            await this.profilesService.UpdateAsync(input.Id, input, user.Id);

            return(this.Redirect($"/Profiles/Index?petId={input.Id}"));
        }
示例#8
0
        public ActionResult <EditProfileResponseModel> EditProfile([FromBody] EditProfileInputModel data)
        {
            try
            {
                EditProfileResponseModel res = new EditProfileResponseModel();

                ProfileBL bl = new ProfileBL(DbContext);

                var output = bl.EditProfile(data);

                res.data     = output;
                res.Message  = "Success update data";
                res.Response = true;

                return(res);
            }
            catch (Exception ex)
            {
                EditProfileResponseModel logres = new EditProfileResponseModel();
                logres.Message  = ex.Message;
                logres.Response = false;

                return(logres);
            }
        }
示例#9
0
        public async Task <IActionResult> Profile(EditProfileInputModel model)
        {
            if (ModelState.IsValid)
            {
                await this.userService.EditUser(model);
            }

            return(this.Redirect("/User/Profile"));
        }
        public async Task UpdateAsyncDoesntUpdateWithNonExistentId()
        {
            await this.SeedData();

            var input = new EditProfileInputModel();

            await this.profilesService.UpdateAsync("test2", input, "test");

            Assert.Equal("test", (await this.profileRepository.All().FirstOrDefaultAsync()).FirstName);
        }
示例#11
0
        public void ShouldUpdateYourPetProfileWithImage()
        {
            var listImage     = new List <Image>();
            var mockRepoImage = new Mock <IDeletableEntityRepository <Image> >();

            mockRepoImage.Setup(x => x.All()).Returns(listImage.AsQueryable());
            mockRepoImage.Setup(x => x.AddAsync(It.IsAny <Image>()));
            mockRepoImage.Setup(x => x.Delete(It.IsAny <Image>()));

            var listPet     = new List <Pet>();
            var mockRepoPet = new Mock <IDeletableEntityRepository <Pet> >();

            mockRepoPet.Setup(x => x.All()).Returns(listPet.AsQueryable());
            mockRepoPet.Setup(x => x.AddAsync(It.IsAny <Pet>()));
            mockRepoPet.Setup(x => x.Delete(It.IsAny <Pet>()));

            var listUser     = new List <ApplicationUser>();
            var mockRepoUser = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            mockRepoUser.Setup(x => x.All()).Returns(listUser.AsQueryable());
            mockRepoUser.Setup(x => x.Delete(It.IsAny <ApplicationUser>()));
            var service = new ProfilesService(mockRepoPet.Object, mockRepoUser.Object, mockRepoImage.Object);

            var imageList = new List <string>()
            {
                "vasko.com",
            };


            var pet = new Pet
            {
                BreedId       = 1,
                CityId        = 1,
                Id            = 1,
                Name          = "GoshoCat",
                DateOfBirth   = new DateTime(2008, 3, 1, 7, 0, 0),
                SpecieId      = 1,
                AddedByUserId = "PeshoId",
                Description   = "test",
                Images        = listImage,
            };

            listPet.Add(pet);
            var viewModel = new EditProfileInputModel
            {
                Description = "newTest",
                Id          = 1,
                Name        = "newGoshoCat",
            };

            service.UpdateAsync(1, viewModel, "PeshoId", imageList);
            Assert.Equal("newGoshoCat", pet.Name);
            Assert.Equal("newTest", pet.Description);
        }
示例#12
0
        public async Task UpdateAsync(int id, EditProfileInputModel input, string userId)
        {
            var profiles = this.petsRepository.All().FirstOrDefault(x => x.Id == id);

            profiles.Name = input.Name;
            if (input.Description != null)
            {
                profiles.Description = input.Description;
            }

            await this.petsRepository.SaveChangesAsync();
        }
        public void EditProfile_returns_true_when_correct()
        {
            var user = this.dbService.DbContext.Users.FirstOrDefault(u => u.Id == TestsConstants.TestId);

            var model = new EditProfileInputModel {
                Username = TestsConstants.TestUsername1, Gender = TestsConstants.TestGender, Location = TestsConstants.TestLocation1
            };

            var actualResult = this.settingsService.EditProfile(user, model);

            Assert.True(actualResult == true);

            this.SeedDb();
        }
示例#14
0
        public async Task <IActionResult> ProfileEdit(EditProfileInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                var userFromDb = await this.userManager.FindByNameAsync(this.User.Identity.Name);

                userFromDb.Birthday = model.Birthday;
                userFromDb.FullName = model.FullName;
                await this.userManager.UpdateAsync(userFromDb);

                return(this.Redirect("/Home/IndexLoggedin"));
            }

            return(this.Content($"Please fill both your Birthday and Full Name"));
        }
        public async Task UpdateAsyncWorksCorrectly()
        {
            await this.SeedData();

            var input = new EditProfileInputModel()
            {
                FirstName = "test2",
                Image     = null,
                Gender    = "Male",
                CountryId = 1,
            };

            await this.profilesService.UpdateAsync("test", input, "test");

            Assert.Equal("test2", (await this.profileRepository.All().FirstOrDefaultAsync()).FirstName);
        }
        public async Task <IActionResult> EditProfile()
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var viewUser = new EditProfileInputModel
            {
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                BirthDay    = user.BirthDay,
                Description = user.Description,
                Town        = user.Town,
                CreatedOn   = user.CreatedOn.ToString(),
                PictureURL  = await this.newsFeedService.LastProfilePictureAsync(user.Id),
            };

            return(this.View(viewUser));
        }
        public async Task <ActionResult> Edit(int id, EditProfileInputModel inputModel)
        {
            var profile = await this.profiles.GetByUserId <Profile>(this.currentUser.UserId);

            if (id != profile.Id)
            {
                return(this.BadRequest());
            }

            profile.Description = inputModel.Description;
            profile.Image       = inputModel.Image;
            profile.BirthDate   = inputModel.BirthDate;

            await this.profiles.Save(profile);

            return(this.Ok());
        }
        public EditProfileInputModel EditProfile(string loggedInUserId, EditProfileInputModel model)
        {
            this.CheckModelForNull(model);

            var user = this.GetUserById(loggedInUserId);

            user.Fullname = model.Fullname;
            user.Email    = model.Email;
            user.UserName = model.Username;
            Mapper.Map(model, user);

            this.Data.SaveChanges();

            var viewModel = Mapper.Map <EditProfileInputModel>(user);

            return(viewModel);
        }
        public async Task UpdateAsyncWorksCorrectlyWithImage()
        {
            await this.SeedData();

            var imageMock = new Mock <IFormFile>();

            imageMock.Setup(x => x.Length).Returns(1);
            var input = new EditProfileInputModel()
            {
                FirstName = "test2",
                Image     = imageMock.Object,
                Gender    = "Male",
                CountryId = 1,
            };

            await this.profilesService.UpdateAsync("test", input, "test");

            Assert.Equal("test2", (await this.profileRepository.All().FirstOrDefaultAsync()).FirstName);
        }
        public ActionResult EditProfile(EditProfileInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    var profile = this.profileService.EditProfile(this.LoggedInUserId, model);
                    this.AddNotification("User profile was edited successfully", NotificationType.SUCCESS);
                    return(this.View(profile));
                }
                catch (Exception ex)
                {
                    this.AddNotification(ex.Message, NotificationType.ERROR);
                    return(this.View(model));
                }
            }

            return(this.View(model));
        }
示例#21
0
        public async Task <IActionResult> ChangePhoto(EditProfileInputModel inputModel)
        {
            if (inputModel.PhotoFile == null)
            {
                return(this.Redirect("/User/Profile"));
            }

            bool isFileValid = this.userService.IsFileValid(inputModel.PhotoFile);

            if (isFileValid == false)
            {
                return(this.RedirectToAction("Profile"));
            }

            User user = await this._userManager.GetUserAsync(User);

            //Change only user's photo without checking other data
            await this.userService.ChangeProfilePicture(user, inputModel.PhotoFile);

            return(this.Redirect("/User/Profile"));
        }
        public IActionResult EditProfile(EditProfileInputModel model)
        {
            var user = this.accountService.GetUserByName(this.User.Identity.Name, this.ModelState);

            var passwordCheck = this.settingsService.CheckPassword(user, model.Password, this.ModelState);

            if (ModelState.IsValid)
            {
                this.accountService.LogoutUser();

                this.settingsService.EditProfile(user, model);

                return(this.Redirect("/"));
            }
            else
            {
                var result = this.View("Error", ModelState);
                result.StatusCode = (int)HttpStatusCode.BadRequest;

                return(result);
            }
        }
        public ActionResult EditProfile(EditProfileInputModel model)
        {
            if (this.User.Identity.GetUserName() != model.BaseModel.CurrentUsername)
            {
                throw new Exception("Not auhtorized.");
            }

            if (!this.ModelState.IsValid)
            {
                return this.View("~/Areas/UserProfile/Views/Profile/EditProfile.cshtml", model);
            }

            this.userServices.Update(
                this.User.Identity.GetUserId(),
                model.Email,
                model.FirstName,
                model.LastName,
                model.PhoneNumber,
                model.Description);

            return this.RedirectToAction("Index", new { username = model.BaseModel.CurrentUsername });
        }
示例#24
0
        public async Task <IActionResult> Edit(EditProfileInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input.CountriesItems = this.countriesService.GetAllAsKvp();
                return(this.View(input));
            }

            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            try
            {
                await this.profilesService.UpdateAsync(userId, input, $"{this.webHost.WebRootPath}/img/users");
            }
            catch (ArgumentException ae)
            {
                this.ModelState.AddModelError(string.Empty, ae.Message);
                input.CountriesItems = this.countriesService.GetAllAsKvp();
                return(this.View(input));
            }

            return(this.RedirectToAction(nameof(this.ById), new { input.Id }));
        }
示例#25
0
        public EditProfileOutputModel EditProfile(EditProfileInputModel data)
        {
            DateTime?today = DateTime.Now;

            User user = new User();

            user.FirstName          = data.FirstName;
            user.LastName           = data.LastName;
            user.ID                 = data.UserID;
            user.UserName           = data.UserName;
            user.PhoneNumber        = data.NoTelp;
            user.LastUpdateByUserID = data.UserID;
            user.LastUpdateDate     = today;

            UserRepository userRepo = new UserRepository(db);

            userRepo.Update(user, false);

            Company comp = new Company();

            comp.UserID      = data.UserID;
            comp.NPWP        = data.NPWP;
            comp.Website     = data.Website;
            comp.Alamat      = data.Alamat;
            comp.CompanyName = data.NamaPerusahaan;
            comp.Email       = data.EmailPerusahaan;
            comp.Note        = data.Catatan;
            comp.Kategory    = data.Kategori;


            CompanyRepository compRepo = new CompanyRepository(db);

            compRepo.Update(comp, false);

            ContactPerson cp = new ContactPerson();

            cp.Email  = data.EmailPIC;
            cp.Name   = data.FirstName + " " + data.LastName;
            cp.UserID = data.UserID;

            ContactPersonRepository cpRepo = new ContactPersonRepository(db);

            cpRepo.Update(cp, true);


            var query = (from u in db.User
                         join c in db.Company on u.ID equals c.UserID
                         where u.ID == data.UserID
                         select new EditProfileOutputModel()
            {
                EmailPerusahaan = c.Email,
                EmailPIC = u.UserName,
                Alamat = c.Alamat,
                Catatan = c.Note,
                FirstName = u.FirstName,
                LastName = u.LastName,
                NamaPerusahaan = c.CompanyName,
                NoTelp = u.PhoneNumber,
                NPWP = c.NPWP,
                PhotoUrl = u.PhotoUrl,
                UserID = u.ID,
                UserName = u.UserName,
                Website = c.Website,
                Kategori = c.Kategory
            });

            return(query.FirstOrDefault());
        }