public HttpResponseMessage Update(HttpRequestMessage request, CourseUserViewModel post) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var courseUserDb = _courseUserService.GetCourseUser(post.ID); if (courseUserDb == null) { response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid."); } else { courseUserDb.UpdateCourseUser(post); _courseUserService.UpdateCourseUser(courseUserDb); _courseUserService.SaveCourseUser(); response = request.CreateResponse <CourseUserViewModel>(HttpStatusCode.OK, post); } } return response; })); }
public HttpResponseMessage Add(HttpRequestMessage request, CourseUserViewModel post) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { CourseUser newPost = new CourseUser(); newPost.UpdateCourseUser(post); newPost.CreatedDate = DateTime.Now; newPost.CreatedBy = User.Identity.Name; _courseUserService.CreateCourseUser(newPost); _courseUserService.SaveCourseUser(); // Update view model post = Mapper.Map <CourseUser, CourseUserViewModel>(newPost); response = request.CreateResponse <CourseUserViewModel>(HttpStatusCode.Created, post); } return response; })); }
public static void UpdateCourseUser(this CourseUser courseUser, CourseUserViewModel courseUserViewModel, string action = "add") { courseUser.ID = courseUserViewModel.ID; courseUser.UserId = courseUserViewModel.UserId; courseUser.CourseId = courseUserViewModel.CourseId; courseUser.Price = courseUserViewModel.Price; courseUser.PaymentMethodId = courseUserViewModel.PaymentMethodId; if (action == "add") { courseUser.CreatedDate = courseUserViewModel.CreatedDate; } courseUser.CreatedBy = courseUserViewModel.CreatedBy; courseUser.Status = courseUserViewModel.Status; }
public ActionResult Index() { var model = new CourseUserViewModel(); foreach (Course c in MySenseiDb.Courses.ToList()) { var ftCourse = new FtCourseViewModel() { Description = c.Description, Id = c.CourseID, ImageUrl = c.Picture, Price = Convert.ToDecimal(c.Price), Title = c.Title }; model.addFTCourse(ftCourse); } foreach (User u in MySenseiDb.Users.ToList()) { if (u.OfferedCourses.Count < 10) { var ftTeacher = new FtTeacherViewModel() { Description = u.Description, Id = u.UserId, ImageUrl = u.ProfilePicture, name = u.Fullname }; model.addFTTeacher(ftTeacher); } } return View(model); }