public async Task <IActionResult> ApplyDiscountCourse(List <int> lstCourseHasChoose, int idDiscount) { quanlykhoahocContext context = _courseService.GetContext(); bool status = false; using (IDbContextTransaction transaction = context.Database.BeginTransaction()) { foreach (var item in lstCourseHasChoose) { try { DiscountCourse discountCourse = new DiscountCourse(); discountCourse.Idcourse = item; discountCourse.Iddiscount = idDiscount; await _discountCourseService.CreateAsync(discountCourse); } catch { status = false; transaction.Rollback(); } } status = true; transaction.Commit(); } return(Json(new { status = status })); }
public async Task <IActionResult> Delete(int ID) { if (ID == 0) { return(NotFound()); } try { string name1 = Directory.GetCurrentDirectory(); quanlykhoahocContext context = _courseLessonService.GetContext(); using (IDbContextTransaction transaction = context.Database.BeginTransaction()) { try { var model = _courseLessonService.GetById(ID); var idCourse = _chapterService.GetCondition(m => m.Id == model.ChapterId).Select(m => m.CourseId).FirstOrDefault(); var listUpdateOrderSort = _courseLessonService.GetCondition(m => m.SortOrder > model.SortOrder).Select(m => m).ToList(); var softOrderCurrent = model.SortOrder - 1; await _courseLessonService.Delete(ID); foreach (var item in listUpdateOrderSort) { var modelUpdateOrderSoft = _courseLessonService.GetById(item.Id); modelUpdateOrderSoft.SortOrder = softOrderCurrent++; await _courseLessonService.UpdateAsync(modelUpdateOrderSoft); } if (!string.IsNullOrEmpty(model.VideoPath)) { string urlVideo = name1 + @"\wwwroot\" + model.VideoPath; if (CheckFile(urlVideo)) { System.IO.File.Delete(urlVideo); } } if (!string.IsNullOrEmpty(model.SlidePath)) { string urlSlide = name1 + @"\wwwroot\" + model.SlidePath; if (CheckFile(urlSlide)) { System.IO.File.Delete(urlSlide); } } transaction.Commit(); return(RedirectToAction("Detail", "Course", new { ID = idCourse })); } catch (Exception ex) { transaction.Rollback(); Console.WriteLine("Error occurred."); return(NotFound()); } } } catch (Exception ex) { return(NotFound()); } }
public DashboardController(IMapper mapper, ICourseService courseService, IOrderService orderService) { _orderService = orderService; _courseService = courseService; _mapper = mapper; _context = _courseService.GetContext(); }
public LessonCommentController(ILessonCommentService lessonCommentService, IHostingEnvironment hostingEnvironment, IMapper mapper ) { _hostingEnvironment = hostingEnvironment; _lessonCommentService = lessonCommentService; _mapper = mapper; _context = _lessonCommentService.GetContext(); }
public CourseLessonService(quanlykhoahocContext context) : base(context) { }
public LessonCommentService(quanlykhoahocContext context) : base(context) { }
public ChapterService(quanlykhoahocContext context) : base(context) { }
public OrderService(quanlykhoahocContext context) : base(context) { }
protected RepositoryBaseService(quanlykhoahocContext context) { this._context = context; dbSet = _context.Set <T>(); }
public WareHouseService(quanlykhoahocContext context) : base(context) { }
public DiscountCourseService(quanlykhoahocContext context) : base(context) { }
public async Task <IActionResult> PaymentComplete(string listIdCourse) { PaymentVM vm = ComputePayment(listIdCourse); long totalamount = 0; if (User.Identity.IsAuthenticated) { if (vm.lstCourse != null && vm.lstCourse.Count > 0) { try { ClaimsPrincipal currentUser = this.User; var currentUserName = int.Parse(currentUser.FindFirst(ClaimTypes.NameIdentifier).Value); quanlykhoahocContext context = _courseService.GetContext(); using (IDbContextTransaction transaction = context.Database.BeginTransaction()) { try { string orderId = Guid.NewGuid().ToString(); foreach (var item in vm.lstCourse) { var course = _courseService.GetById(item.Id); if (course != null) { totalamount += course.Price; OrderDetails orderDetails = new OrderDetails(); orderDetails.OrderId = orderId; orderDetails.CourseId = course.Id; orderDetails.Amount = course.Price; await _orderDetailService.CreateAsync(orderDetails); } else { transaction.Rollback(); return(Json(new { status = false, loca = "" })); } } string convertTotal = totalamount.ToString(); long amount = Convert.ToInt64(convertTotal); string endpoint = DefinePaymentMomo.MomoTest; string requestId = Guid.NewGuid().ToString(); string orderInfo = "PaymentCourse"; string extraData = ""; Orders orderVM = new Orders(); orderVM.Id = orderId; orderVM.OrderDate = DateTime.Now; orderVM.PayMethod = PaymentMethod.MomoPay; //trang thai chua thanh cong orderVM.Status = OrderStatus.Unpaid; orderVM.TotalAmount = totalamount; //tao chu ky dien tu string signature = string.Empty; orderVM.Signature = signature = SignatureMomo(requestId, amount.ToString(), orderId, orderInfo, extraData); orderVM.RequestId = requestId; orderVM.UserId = currentUserName; await _orderService.CreateAsync(orderVM); string result = await CallMomo(signature, requestId, amount.ToString(), orderId, orderInfo, extraData); //yeu cau cung cap url thanh toan ReposonsePayMomo reposonsePayMomo = JsonConvert.DeserializeObject <ReposonsePayMomo>(result); if (reposonsePayMomo.errorCode == "0") { string signatureReponse = SignatureCheckResponseMomo(requestId, orderId, reposonsePayMomo.message, reposonsePayMomo.localMessage, reposonsePayMomo.payUrl, reposonsePayMomo.errorCode, reposonsePayMomo.requestType); if (signatureReponse == reposonsePayMomo.signature) { transaction.Commit(); return(Json(new { status = true, loca = reposonsePayMomo.payUrl })); } else { transaction.Rollback(); return(Json(new { status = false, loca = "" })); } } } catch { transaction.Rollback(); return(Json(new { status = false, loca = "" })); } } } catch (Exception ex) { return(Json(new { status = false, loca = "" })); } } } return(Json(new { status = false, loca = "" })); }
public CourseCategoryService(quanlykhoahocContext context) : base(context) { }
public CartService(quanlykhoahocContext context) : base(context) { }