Ejemplo n.º 1
0
        /// <summary>
        /// Updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto UpdateLesson(LessonEditDto itemToSave, Guid accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity == null)
                {
                    result.Error = "ERR-LESSON-NOT-EXISTS";
                    return(result);
                }

                if (entity.AccountId != accountId)
                {
                    result.Error = "ERR-LESSON-ACCOUNT-INVALID";
                    return(result);
                }

                entity.DayId     = itemToSave.DayId;
                entity.FromDate  = DateTimeHelper.StringToDateTime(itemToSave.FromDate);
                entity.ToDate    = DateTimeHelper.StringToDateTime(itemToSave.ToDate);
                entity.SubjectId = itemToSave.SubjectId;
                entity.TeacherId = itemToSave.TeacherId;
                entity.RoomId    = itemToSave.RoomId;
                entity.Remark    = itemToSave.Remark;
                entity.ModDate   = DateTime.Now;
                entity.ModUser   = Environment.UserName;

                ctx.SaveChanges();
                result.Success = true;
                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Inserts or updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto InsertUpdateLesson(LessonEditDto itemToSave, Guid accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity != null)
                {
                    result.Error = "ERR-LESSON-ALREADY-EXISTS";
                    return(result);
                }

                if (!new DayServerService().DayExists(itemToSave.DayId, ctx))
                {
                    result.Error = "ERR-LESSON-DAY-NOT-EXISTS";
                    return(result);
                }

                if (!new SubjectServerService().SubjectExists(itemToSave.SubjectId, ctx))
                {
                    result.Error = "ERR-LESSON-SUBJECT-NOT-EXISTS";
                    return(result);
                }

                if (itemToSave.TeacherId.HasValue && !new TeacherServerService().TeacherExists(itemToSave.TeacherId.Value, ctx))
                {
                    result.Error = "ERR-LESSON-TEACHER-NOT-EXISTS";
                    return(result);
                }

                if (itemToSave.RoomId.HasValue && !new RoomServerService().RoomExists(itemToSave.RoomId.Value, ctx))
                {
                    result.Error = "ERR-LESSON-ROOM-NOT-EXISTS";
                    return(result);
                }

                entity           = new LessonEntity();
                entity.Id        = itemToSave.Id;
                entity.AccountId = accountId;
                entity.DayId     = itemToSave.DayId;
                entity.FromDate  = DateTimeHelper.StringToDateTime(itemToSave.FromDate);
                entity.ToDate    = DateTimeHelper.StringToDateTime(itemToSave.ToDate);
                entity.SubjectId = itemToSave.SubjectId;
                entity.TeacherId = itemToSave.TeacherId;
                entity.RoomId    = itemToSave.RoomId;
                entity.Remark    = itemToSave.Remark;
                entity.ModDate   = DateTime.Now;
                entity.ModUser   = Environment.UserName;
                ctx.LessonSet.Add(entity);

                ctx.SaveChanges();
                result.Success = true;
                return(result);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <returns></returns>
        public ResultDto UpdateLesson(LessonEditDto itemToSave)
        {
            this.SetResponseHeaderCacheExpiration();

            AccountPassword      credentials    = this.GetCredentialsFromRequest();
            AccountServerService accountService = new AccountServerService();
            Guid accountId = accountService.GetAccountId(credentials.Account);

            LessonServerService service = new LessonServerService();

            return(service.InsertUpdateLesson(itemToSave, accountId));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Fills the lesson edit data transfer object.
 /// </summary>
 /// <param name="item">The item to fill.</param>
 /// <param name="entity">The entity.</param>
 /// <returns>The filled item.</returns>
 private LessonEditDto FillLessonEditDto(LessonEditDto item, LessonEntity entity)
 {
     item.Id          = entity.Id;
     item.DayId       = entity.DayId;
     item.DayCaption  = entity.DayNavProp.Caption;
     item.FromDate    = DateTimeHelper.DateTimeToString(entity.FromDate);
     item.ToDate      = DateTimeHelper.DateTimeToString(entity.ToDate);
     item.SubjectId   = entity.SubjectId;
     item.SubjectCode = entity.SubjectNavProp.Code;
     item.TeacherId   = entity.TeacherId;
     item.RoomId      = entity.RoomId;
     item.Remark      = entity.Remark;
     return(item);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the lesson.
        /// </summary>
        /// <param name="id">The lesson identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The lesson data.</returns>
        public LessonEditDto GetLesson(Guid id, Guid accountId)
        {
            LessonEditDto data = null;

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == id && f.AccountId == accountId);
                if (entity != null)
                {
                    data = this.FillLessonEditDto(new LessonEditDto(), entity);
                }
            }

            return(data);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the lessons of a day.
        /// </summary>
        /// <param name="dayId">The day identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The lessons of the day.</returns>
        public List <LessonEditDto> GetLessonsOfDay(Guid dayId, Guid accountId)
        {
            List <LessonEditDto> data = new List <LessonEditDto>();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                IQueryable <LessonEntity> entities = ctx.LessonSet.Where(f => f.DayId == dayId && f.AccountId == accountId);
                foreach (LessonEntity entity in entities)
                {
                    LessonEditDto item = this.FillLessonEditDto(new LessonEditDto(), entity);
                    data.Add(item);
                }
            }

            return(data);
        }
Ejemplo n.º 7
0
        public bool LessonEdit(LessonEditDto lessonDto)
        {
            if (lessonDto.classId == Guid.Empty ||
                !DateTime.TryParse(lessonDto.date, out var date) ||
                string.IsNullOrEmpty(lessonDto.teacherName) ||
                lessonDto.teacherId == Guid.Empty ||
                lessonDto.subjectId == Guid.Empty)
            {
                var dateTime = DateTime.Parse(lessonDto.date);

                var teacherModel = _teacherService.GetTeacherModel(lessonDto.teacherId);

                var viewModel = new LessonEditModel();
                viewModel.DateTime    = dateTime;
                viewModel.ClassId     = lessonDto.classId;
                viewModel.Classes     = _classService.GetClasses().ToDictionary(x => x.Id, y => y.FullName);
                viewModel.TeacherId   = lessonDto.teacherId;
                viewModel.TeacherName = teacherModel != null ? teacherModel.Name : string.Empty;
                viewModel.Subjects    = _repoSubject.GetAllItems().ToDictionary(x => x.Id, y => y.Name);
                viewModel.SubjectId   = lessonDto.schedId;
                viewModel.Id          = lessonDto.schedId;

                ViewBag.IsInvalid = true;
                return(false);
            }

            var schedModel = Activator.CreateInstance <ScheduleModel>();

            schedModel.Id    = lessonDto.schedId;
            schedModel.Date  = DateTime.Parse(lessonDto.date);
            schedModel.Class = new ClassModel {
                Id = lessonDto.classId
            };
            schedModel.Teacher = new TeacherModel {
                Id = lessonDto.teacherId
            };
            schedModel.Subject = _repoSubject.GetAllItems().FirstOrDefault(x => x.Id == lessonDto.subjectId).Name;

            _scheduleService.UpdateSchedule(schedModel);

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <returns></returns>
        public ResultDto UpdateLesson(LessonEditDto itemToSave)
        {
            this.SetResponseHeaderCacheExpiration();

            AccountPassword credentials = this.GetCredentialsFromRequest();
            AccountServerService accountService = new AccountServerService();
            Guid accountId = accountService.GetAccountId(credentials.Account);

            LessonServerService service = new LessonServerService();
            return service.InsertUpdateLesson(itemToSave, accountId);
        }
 /// <summary>
 /// Fills the lesson edit data transfer object.
 /// </summary>
 /// <param name="item">The item to fill.</param>
 /// <param name="entity">The entity.</param>
 /// <returns>The filled item.</returns>
 private LessonEditDto FillLessonEditDto(LessonEditDto item, LessonEntity entity)
 {
     item.Id = entity.Id;
     item.DayId = entity.DayId;
     item.DayCaption = entity.DayNavProp.Caption;
     item.FromDate = DateTimeHelper.DateTimeToString(entity.FromDate);
     item.ToDate = DateTimeHelper.DateTimeToString(entity.ToDate);
     item.SubjectId = entity.SubjectId;
     item.SubjectCode = entity.SubjectNavProp.Code;
     item.TeacherId = entity.TeacherId;
     item.RoomId = entity.RoomId;
     item.Remark = entity.Remark;
     return item;
 }
        /// <summary>
        /// Updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto UpdateLesson(LessonEditDto itemToSave, Guid accountId)
        {
            ResultDto result = new ResultDto();
            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity == null)
                {
                    result.Error = "ERR-LESSON-NOT-EXISTS";
                    return result;
                }

                if (entity.AccountId != accountId)
                {
                    result.Error = "ERR-LESSON-ACCOUNT-INVALID";
                    return result;
                }

                entity.DayId = itemToSave.DayId;
                entity.FromDate = DateTimeHelper.StringToDateTime(itemToSave.FromDate);
                entity.ToDate = DateTimeHelper.StringToDateTime(itemToSave.ToDate);
                entity.SubjectId = itemToSave.SubjectId;
                entity.TeacherId = itemToSave.TeacherId;
                entity.RoomId = itemToSave.RoomId;
                entity.Remark = itemToSave.Remark;
                entity.ModDate = DateTime.Now;
                entity.ModUser = Environment.UserName;

                ctx.SaveChanges();
                result.Success = true;
                return result;
            }
        }
        /// <summary>
        /// Inserts or updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto InsertUpdateLesson(LessonEditDto itemToSave, Guid accountId)
        {
            ResultDto result = new ResultDto();
            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity != null)
                {
                    result.Error = "ERR-LESSON-ALREADY-EXISTS";
                    return result;
                }

                if (!new DayServerService().DayExists(itemToSave.DayId, ctx))
                {
                    result.Error = "ERR-LESSON-DAY-NOT-EXISTS";
                    return result;
                }

                if (!new SubjectServerService().SubjectExists(itemToSave.SubjectId, ctx))
                {
                    result.Error = "ERR-LESSON-SUBJECT-NOT-EXISTS";
                    return result;
                }

                if (itemToSave.TeacherId.HasValue && !new TeacherServerService().TeacherExists(itemToSave.TeacherId.Value, ctx))
                {
                    result.Error = "ERR-LESSON-TEACHER-NOT-EXISTS";
                    return result;
                }

                if (itemToSave.RoomId.HasValue && !new RoomServerService().RoomExists(itemToSave.RoomId.Value, ctx))
                {
                    result.Error = "ERR-LESSON-ROOM-NOT-EXISTS";
                    return result;
                }

                entity = new LessonEntity();
                entity.Id = itemToSave.Id;
                entity.AccountId = accountId;
                entity.DayId = itemToSave.DayId;
                entity.FromDate = DateTimeHelper.StringToDateTime(itemToSave.FromDate);
                entity.ToDate = DateTimeHelper.StringToDateTime(itemToSave.ToDate);
                entity.SubjectId = itemToSave.SubjectId;
                entity.TeacherId = itemToSave.TeacherId;
                entity.RoomId = itemToSave.RoomId;
                entity.Remark = itemToSave.Remark;
                entity.ModDate = DateTime.Now;
                entity.ModUser = Environment.UserName;
                ctx.LessonSet.Add(entity);

                ctx.SaveChanges();
                result.Success = true;
                return result;
            }
        }
        public void GetLesson_InvalidId_ReturnsNull()
        {
            LessonEditDto item = this.service.GetLesson(Guid.NewGuid(), new Guid("FDB44E7C-AB09-4DF2-9CA9-C42D001E2957"));

            Assert.IsNull(item);
        }