public async Task <UserInfoViewModel> Register(RegisterViewModel model) { var userFromRepository = _eJContext.Users.Add(new User() { Email = model.Email, Password = GetPasswordBytes(model.Password), RoleId = (int)RolesEnum.Студент, BirthDay = model.Birthday, FName = model.FName, SName = model.SName, MName = model.MName, PersonalNumber = model.PersonalNumber, StartDate = model.StartDate, Sex = model.Sex, UserStateId = (int)UserStatesEnum.Studying, GroupId = model.GroupId }); if (userFromRepository == null) { return(null); } var code = await AuthorizationService.GenerateEmailConfirmationTokenAsync(userFromRepository.Entity); _eJContext.SaveChanges(); return(new UserInfoViewModel { Fio = userFromRepository.Entity.Fio, Role = (RolesEnum)userFromRepository.Entity.RoleId, Email = userFromRepository.Entity.Email, Id = userFromRepository.Entity.Id, Code = code }); }
public CourseViewModel AddCourse(CourseViewModel course) { var courseToRepository = new Course { Number = course.Number, EndDate = course.EndDate, StartDate = course.StartDate }; var courseAdded = Mapper.Map <CourseViewModel>(_eJContext.Courses.Add(courseToRepository)); _eJContext.SaveChanges(); return(courseAdded); }
public ObjectResult SynchronizeSheduleAndSemester(DateTime startSemesterDate, int weekNumber) { var semester = _eJContext.Semesters.FirstOrDefault(x => x.StartDate == startSemesterDate); var culture = new System.Globalization.CultureInfo("ru-RU"); if (semester != null) { var currentDate = startSemesterDate; while (currentDate != semester.EndDate.AddDays(1)) { var day = culture.DateTimeFormat.GetDayName(currentDate.DayOfWeek); if (currentDate.DayOfWeek == 0) { weekNumber = weekNumber == 1 ? 2 : 1; currentDate = currentDate.AddDays(1); } else { var weekDay = _eJContext.WeekDays.FirstOrDefault(x => x.NumberOfWeek == weekNumber && x.Day.ToLower() == day.ToLower()); if (weekDay != null) { var calendar = _eJContext.Calendars?.FirstOrDefault(x => x.Date == currentDate) ?? _eJContext.Calendars.Add(new Calendar { Date = currentDate }).Entity; var sheduleTimeSpendings = _eJContext.SheduleTimeSpendings.Where(x => x.WeekDayId == weekDay.Id); if (calendar != null && sheduleTimeSpendings.Count() != 0) { foreach (var sheduleTimeSpending in sheduleTimeSpendings) { if (!_eJContext.CalendarSheduleTimeSpendings.Any(x => x.SheduleTimeSpendingId == sheduleTimeSpending.Id && x.CalendarId == calendar.Id)) { _eJContext.CalendarSheduleTimeSpendings.Add(new CalendarSheduleTimeSpending { CalendarId = calendar.Id, SheduleTimeSpendingId = sheduleTimeSpending.Id }); } } } currentDate = currentDate.AddDays(1); } } } _eJContext.SaveChanges(); } return(new OkObjectResult(true)); }
public GroupViewModel AddGroup(GroupViewModel group) { var groupToRepository = new Group { Number = group.Number, EndDate = group.EndDate, StartDate = group.StartDate, HalfGroup = group.HalfGroup, CourseId = group.CourseId }; var groupAdded = Mapper.Map <GroupViewModel>(_eJContext.Groups.Add(groupToRepository)); _eJContext.SaveChanges(); return(groupAdded); }