public ContentResult SuccessToOrder(int orderId) { OrderToCourse order = context.OrdersToCourse.Find(orderId); RequestStatus status = new RequestStatus(); if (order != null) { order.Status = true; order.Course.Students.Add(order.Student); var baseOrder = order.Course.BaseAccessProps.MakeClone(); baseOrder.Student = order.Student; order.Course.StudentAccessProps.Add(baseOrder); context.Entry(order).State = EntityState.Modified; context.SaveChanges(); status.Result = true; status.ErrorMessage = "No errors"; } else { status.Result = false; status.ErrorMessage = "Cannod find order"; } var json = new JavaScriptSerializer().Serialize(status); return(new ContentResult() { Content = json, ContentType = ApplicationConstants.JSON_TYPE }); }
public async Task <SudentAddToCourseStatus> SendOrderToCourse(string email, int courseId) { try { Student sturent = context.Students.FirstOrDefault(x => x.Email == email); if (sturent == null) { return(new SudentAddToCourseStatus(email, false, StudentRegResults.Exception, new List <string> { "The email " + email + " is not available" })); } Course course = context.Courses.Find(courseId); if (course.Students.Contains(sturent)) { return(new SudentAddToCourseStatus(email, false, StudentRegResults.AlreadyParticipate, new List <string> { "The email " + email + " is already student in this course" })); } if (AlreadyHasOrder(courseId, email)) { return(new SudentAddToCourseStatus(email, false, StudentRegResults.AlreadyOrdered, new List <string> { "This email " + email + " is already orderd" })); } OrderToCourse order = new OrderToCourse(course, sturent); context.OrdersToCourse.Add(order); await context.SaveChangesAsync(); return(new SudentAddToCourseStatus(email, false, StudentRegResults.OK, new List <string> { "No errors" })); } catch (Exception ex) { return(new SudentAddToCourseStatus(email, false, StudentRegResults.Exception, new List <string> { ex.Message })); } }
public ContentResult RejectOrderToCourse(int orderId) { OrderToCourse order = context.OrdersToCourse.Find(orderId); RequestStatus status = new RequestStatus(); if (order != null) { context.OrdersToCourse.Remove(order); context.SaveChanges(); } else { status.Result = false; status.ErrorMessage = "Cannod find order"; } var json = new JavaScriptSerializer().Serialize(status); return(new ContentResult() { Content = json, ContentType = ApplicationConstants.JSON_TYPE }); }