public ResponseResult PostNotification(NotificationModel notification) { var newNotification = new Notification { Id = _dbContext.Notificiations.Last().Id + 1, Message = notification.Message, SentOn = notification.SentOn, }; _dbContext.Notificiations.Add(newNotification); var allUsers = _dbContext.Users.ToList(); foreach (var user in allUsers) { foreach (var forUser in notification.ForUsers) { if (user.Id == forUser.Id) { var newUserNotification = new UserNotification { UserId = user.Id, NotificationId = newNotification.Id, }; _dbContext.UserNotifications.Add(newUserNotification); } } } _dbContext.SaveChanges(); return(ResponseResult.Ok); }
public ResponseResult DeleteMember(int userId) { var user = _dbContext.GymUsers.First(gu => gu.RegularUserId == userId); if (user == null) { return(ResponseResult.Error("User not found")); } _dbContext.GymUsers.Remove(user); _dbContext.SaveChanges(); return(ResponseResult.Ok); }
public ResponseResult <RegularUser> RegisterRegularUser(RegistrationModel model) { var password = EncryptionHelper.Hash(model.Password); var regularUser = new RegularUser { Email = model.Email, Name = model.Name, Password = password }; _dbContext.Add(regularUser); _dbContext.SaveChanges(); return(new ResponseResult <RegularUser>(regularUser)); }
public ResponseResult AddEmployee(EmployeeModel employeeModel) { var employee = new Employee { Id = employeeModel.Id, Name = employeeModel.Name, Email = employeeModel.Email, HiredOn = employeeModel.HiredOn, PricePerHour = employeeModel.PricePerHour, EmployeeRole = employeeModel.EmployeeRole, GymId = employeeModel.Gym.Id, }; _dbContext.Employees.Add(employee); _dbContext.SaveChanges(); return(ResponseResult.Ok); }
public ResponseResult AddGym(GymModel gymModel) { var gym = new Gym { Id = gymModel.Id, Name = gymModel.Name, Rating = gymModel.Rating, ContactEmail = gymModel.ContactEmail, Capacity = gymModel.Capacity, Latitude = gymModel.Latitude, Longitude = gymModel.Longitude, StartOfWork = gymModel.StartOfWork, EndOfWork = gymModel.EndOfWork, AdminId = gymModel.Admin.Id, AdressId = gymModel.Adress.Id, }; _dbContext.Gyms.Add(gym); _dbContext.SaveChanges(); return(ResponseResult.Ok); }
public ResponseResult ReserveSchedule(ScheduleModel scheduleModel, int userId) { var user = _dbContext.RegularUsers.FirstOrDefault(u => u.Id == userId); if (user == null) { return(ResponseResult.Error("User not found")); } var newSchedule = new Schedule { GymId = scheduleModel.Gym.Id, RegularUserId = user.Id, Time = scheduleModel.Time }; _dbContext.Schedules.Add(newSchedule); _dbContext.SaveChanges(); return(ResponseResult.Ok); }