Ejemplo n.º 1
0
        public void Save_ValidInputModelWithIdEqualToZero_ReturnsCreatedLessonId()
        {
            var lesson = new Lesson()
            {
                Id          = 0,
                OrderId     = 1,
                StartTime   = new DateTime(2018, 12, 11, 12, 00, 00),
                EndTime     = new DateTime(2018, 12, 11, 13, 0, 0),
                ThemeColor  = "green",
                IsFullDay   = false,
                Subject     = "first lesson",
                Description = "asdfg"
            };
            var returnValue = new List <Lesson>()
            {
                lesson
            };

            this.repository.Setup(r => r.All()).Returns(returnValue.AsQueryable);
            this.repository.Setup(r => r.Update(lesson)).Callback(() => new Lesson()
            {
                Id          = 1,
                OrderId     = 1,
                StartTime   = new DateTime(2018, 12, 11, 12, 00, 00),
                EndTime     = new DateTime(2018, 12, 11, 13, 0, 0),
                ThemeColor  = "green",
                IsFullDay   = false,
                Subject     = "first lesson",
                Description = "new description"
            });
            this.repository.Setup(r => r.AddAsync(lesson)).Returns(Task.FromResult(lesson));

            var model = new FullCalendarInputModel()
            {
                Id          = 0,
                OrderId     = 1,
                TrainerId   = 1,
                StartTime   = new DateTime(2018, 12, 11, 12, 00, 00),
                EndTime     = new DateTime(2018, 12, 11, 13, 0, 0),
                ThemeColor  = "green",
                IsFullDay   = false,
                Subject     = "first lesson",
                Description = "asdfg"
            };

            var result = this.lessonService.Save(model);

            Assert.That(result, Is.EqualTo(0));
        }
Ejemplo n.º 2
0
        public int Save(FullCalendarInputModel model)
        {
            if (model.Id != 0)
            {
                var lessonEditModel = Mapper.Map <EditLessonInputModel>(model);
                var editedLesson    = this.Edit(lessonEditModel).GetAwaiter().GetResult();
                return(editedLesson.Id);
            }
            else
            {
                var lessonCreateModel = Mapper.Map <CreateLessonInputModel>(model);
                var lesson            = this.Create(lessonCreateModel).GetAwaiter().GetResult();

                return(lesson.Id);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Save(FullCalendarInputModel model)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    return(new JsonResult(this.ValidationProblem()));
                }

                if (!this.HasRights(model.Id))
                {
                    throw new OperationCanceledException("You do not have rights for this operation!");
                }

                var result = this.lessonService.Save(model);

                return(this.RedirectToAction("Index", new { trainerId = model.TrainerId }));
            }
            catch (Exception e)
            {
                return(this.View("_Error", e.Message));
            }
        }