public async Task <IActionResult> Create([Bind("UserName,FirstName,LastName,Degree,University,JobPost,Company,Experience")] UserProfile profile, IFormFile CoverImage, IFormFile ProfileImage)
        {
            if (ModelState.IsValid)
            {
                if (ProfileImage != null && ProfileImage.Length > 0)
                {
                    var fileName = Path.GetFileName(ProfileImage.FileName);
                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\items", fileName);
                    using (var fileSteam = new FileStream(filePath, FileMode.Create))
                    {
                        await ProfileImage.CopyToAsync(fileSteam);
                    }
                    profile.ProfileImage = fileName;
                }
                if (CoverImage != null && CoverImage.Length > 0)
                {
                    var fileName = Path.GetFileName(CoverImage.FileName);
                    var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\items", fileName);
                    using (var fileSteam = new FileStream(filePath, FileMode.Create))
                    {
                        await CoverImage.CopyToAsync(fileSteam);
                    }
                    profile.CoverImage = fileName;
                }
                _context.Add(profile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(profile));
        }
Esempio n. 2
0
        public async Task <Tuple <int, string> > InsertUserProfile(User user_in)
        {
            // Tuple<bool, Result<User>> result;
            // if(_context.UserProfiles.Any(uf => uf.Email == user_in.Email)){
            //     result = new Tuple<bool, Result<User>>(false,
            //         new Result<User>(400, "User email already occupied", null));

            //     return result;
            // }

            //id置0
            user_in.UserId = 0;

            Tuple <int, string> result;

            try
            {
                await _context.AddAsync(user_in);

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                result = Tuple.Create(400, "insert failed");
                return(result);
            }

            // result = new Tuple<bool, Result<User>>(true, new Result<User>(200, null, user_in));
            result = Tuple.Create(200, "insert successfully");
            return(result);
        }
Esempio n. 3
0
        public async Task <IActionResult> PutUserProfileModel([FromRoute] int id, [FromBody] UserProfileModel userProfileModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userProfileModel.ID)
            {
                return(BadRequest());
            }

            _context.Entry(userProfileModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserProfileModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("UserID,LastName,FirstMidName,Email,SavedHistoryID,Banned")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("Id,email,profileImgUrl,friendsEmail")] SocialDetails socialDetails)
        {
            if (ModelState.IsValid)
            {
                _context.Add(socialDetails);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(socialDetails));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Slug,Content")] BlogPost blogPost)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blogPost);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogPost));
        }
Esempio n. 7
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind("ID,Name,Number,Company,Email,Skype,LI,FB,VK")] UserProfileModel userProfileModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userProfileModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(MyIndex)));
            }
            return(View(userProfileModel));
        }
Esempio n. 8
0
        public async Task <IActionResult> Create([Bind("Id,userName,alias,website,socialUrl,email,dob")] UserDetails userDetails)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userDetails);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userDetails));
        }
        public async Task <ActionResult <UserProfile> > PostUserProfile([FromBody] UserProfile user)
        {
            try
            {
                _context.UserProfile.Add(user);
                await _context.SaveChangesAsync();


                return(user);
            }

            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw new NotImplementedException();
            }
        }