public IActionResult Create(CreateFriendModel e) { if (ModelState.IsValid) { // Friend friend = friendStore.newFriend(e); // return RedirectToAction("DataFriend", new { id = friend.Id }); string guidImage = null; if (e.Photo != null) { string imagesPath = Path.Combine(_webHostEnvironment.WebRootPath, "images"); guidImage = Guid.NewGuid().ToString() + e.Photo.FileName; string finalRoute = Path.Combine(imagesPath, guidImage); e.Photo.CopyTo(new FileStream(finalRoute, FileMode.Create)); } Friend newFriend = new Friend(); newFriend.Name = e.Name; newFriend.Email = e.Email; newFriend.City = e.City; newFriend.photoRoute = guidImage; friendStore.newFriend(newFriend); return(RedirectToAction("Datafriend", new { id = newFriend.Id })); } return(View()); }
//[Authorize] public IActionResult Create(CreateFriendModel a) { if (ModelState.IsValid) { string guidImagen = null; if (a.Photo != null) { string ficherosImages = Path.Combine(_hosting.WebRootPath, "images"); guidImagen = Guid.NewGuid().ToString() + a.Photo.FileName; string rutaDefenitly = Path.Combine(ficherosImages, guidImagen); a.Photo.CopyTo(new FileStream(rutaDefenitly, FileMode.Create)); } Friend newFriend = new Friend(); newFriend.Name = a.Name; newFriend.Email = a.Email; newFriend.City = a.City; newFriend.routePhoto = guidImagen; _friendStore.nuevo(newFriend); return(RedirectToAction("details", new { id = newFriend.Id })); } return(View()); }
public async Task <FriendResponseModel> CreateFriendAsync(CreateFriendModel model) { var userProfile = await profileRepository.Get(model.UserId); var friendProfile = await profileRepository.Get(model.FriendId); if (userProfile == null && friendProfile == null) { throw new Exception("user profile or friend profile is null, chacked this please"); } if (model.IsFriend == true) { throw new Exception("friend allready cofirmed"); } var friendResponse = mapper.Map <Friend>(model); friendResponse.ProfileFriend = friendProfile; friendResponse.UserProfile = userProfile; friendResponse.FriendProfileId = model.FriendId; friendResponse.UserProfileId = model.UserId; await repository.Add(friendResponse); var userProfileModel = ConvertToProfileModel(userProfile); var friendProfileModel = ConvertToProfileModel(friendProfile); return(Ok(friendProfileModel, userProfileModel, false, false)); }