コード例 #1
0
 public void CreateTest()
 {
     o = ProfileObjectFactory.Create(id, name, location, gender,
                                     birthDay, occupation, aboutText, profileImage);
     validateResults(id, name, location, gender, birthDay,
                     occupation, aboutText, profileImage);
 }
コード例 #2
0
        public async Task <IActionResult> Create(IFormFile avatarFile, [Bind(properties)] ProfileViewModel c)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }

            var    extension = "." + avatarFile.FileName.Split('.')[avatarFile.FileName.Split('.').Length - 1];
            string fileName  = GetUniqueID() + extension;

            var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\" + GetCurrentUserId(), fileName);

            var isCorrectImage = await _imageHandler.UploadImage(avatarFile, path);

            if (!isCorrectImage)
            {
                return(View(c));
            }

            var o = ProfileObjectFactory.Create(GetCurrentUserId(), c.Name, c.Location, c.Gender, c.BirthDay, c.Occupation, c.AboutText, fileName);
            await _profileRepository.AddObject(o);

            return(RedirectToAction(nameof(Details)));
        }