public void Add(Meals_Create model) { var meal = new Meal(model.userid, model.datetime); List <MealDish> dishList = new List <MealDish>(); var dish = _context.Dishes.Find(model.dishid); dishList.Add(new MealDish(meal, dish)); meal.Dishes = dishList; _context.Add(meal); _context.SaveChanges(); }
public void Add(WorkoutCreateVM model) { var workout = new Workout(model.userid, model.starttime, model.endtime); List <WorkoutExcercise> exList = new List <WorkoutExcercise>(); var exercise = _context.Excercises.Find(model.exerciseid); exList.Add(new WorkoutExcercise(workout, exercise)); workout.Excercises = exList; _context.Add(workout); _context.SaveChanges(); }
public ResponseVM CreateNew(RegisterRequest request) { if (_userContext.Users.Any(u => u.Email == request.Email)) { return(new ResponseVM(false)); } var passwordhash = CryptoUtils.GetMD5Hash(request.Password); var newUser = new ApplicationUser(request.Email, passwordhash); var user = _userContext.Add(newUser).Entity; _userContext.SaveChanges(); user = CreateUserToken(user); return(new ResponseVM(true, UserDTO.Create(user))); }