public IHttpActionResult CreateUserProfile(UserProfileCreate profile) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateUserProfileService(); if (!service.CreateUserProfile(profile)) { return(InternalServerError()); } return(Ok()); }
public async Task <UserProfileInfo> CreateAsync(UserProfileCreate createCommand) { var userProfile = new UserProfile() { Email = createCommand.Email, FirstName = createCommand.FirstName, MiddleName = createCommand.MiddleName, LastName = createCommand.LastName, }; await userProfileRepository.AddAsync(userProfile); await unitOfWork.CompleteAsync(); return(userProfile.ToUserProfileInfo()); }
public ActionResult Create(UserProfileCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateUserProfileService(); if (service.CreateUserProfile(model)) { TempData["SaveResult"] = "Your User Profile was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "User Profile could not be created."); return(View(model)); }
public bool CreateUserProfile(UserProfileCreate model) { var entity = new UserProfile() { OwnerId = _userId, UserName = model.UserName, Email = model.Email, ZipCode = model.ZipCode }; using (var ctx = new ApplicationDbContext()) { ctx.UserProfiles.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateUserProfile(UserProfileCreate model) { var entity = new UserProfile() { FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, Email = model.Email, OwnerId = _userId }; using (var ctx = new ApplicationDbContext()) { ctx.UserProfiles.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateUser(UserProfileCreate model) { //List<Activity> allActivities = _db.Activities.ToList(); UserProfile userProfile = new UserProfile() { OwnerId = _userId, UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Age = model.Age, Email = model.Email, // UsersActivities = allActivities.Where(ua => model.ActivityIds.Contains(ua.ActivityId)).ToList() }; _db.UserProfiles.Add(userProfile); return(_db.SaveChanges() > 0); }
public bool CreateUser(UserProfileCreate model) { List <Book> allBooks = _context.Books.ToList(); //Throw exception if DB already contains a profile for this userId if (_context.UserProfiles.Select(p => p.OwnerId).Contains(_userId)) { throw new Exception("A profile for this user already exists."); } UserProfile userProfile = new UserProfile() { OwnerId = _userId, UserName = model.UserName, BookIds = (model.BookIds == null)? null : model.BookIds, BooksToRead = (model.BookIds == null)? null: allBooks.Where(b => model.BookIds.Contains(b.BookId)).ToList() }; _context.UserProfiles.Add(userProfile); return(_context.SaveChanges() > 0); }
public IHttpActionResult PostUserProfile(UserProfileCreate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userProfileService = CreateUserProfileService(); try { if (!userProfileService.CreateUser(model)) { return(InternalServerError()); } return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public bool CreateUserProfile(UserProfileCreate model) { var entity = new UserProfile() { Id = _userId, Title = model.Title, Description = model.Description, CaloryTarget = model.CaloryTarget, CarbTarget = model.CarbTarget, FiberTarget = model.FiberTarget, FatTarget = model.FatTarget, ProteinTarget = model.ProteinTarget, SodiumTarget = model.SodiumTarget, PotassiumTarget = model.PotassiumTarget, CreatedBy = _db.Users.Find(_userId).FirstName + " " + _db.Users.Find(_userId).LastName, CreatedUtc = DateTimeOffset.Now }; _db.UserProfiles.Add(entity); return(_db.SaveChanges() == 1); }
public async Task <IActionResult> Post([FromBody] UserProfileCreate createCommandRequest) { var result = await userProfileService.CreateAsync(createCommandRequest); return(Ok(result)); }