public void givebackRequestConfirm(int id) { using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>()) { // تاریخ شمسی DateTimePersian dt = new DateTimePersian(); string shamsiDate = dt.shamsiDate(); var query = (from br in db.borrowBooks where br.BorrowId == id select br); var result = query.SingleOrDefault(); // کم کردن موجودی var findBook = (from b in db.books where b.BookId == result.BookId select b); var resultBook = findBook.SingleOrDefault(); if (findBook.Count() != 0) { resultBook.BookStock++; db.books.Attach(resultBook); db.Entry(resultBook).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } // به مانت بردن if (query.Count() != 0) { result.Flag = 4; result.DateTimeGiveBack = shamsiDate; db.borrowBooks.Attach(result); db.Entry(result).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); } } }
public void AcceptRequsetConfirm(int id) { DateTimePersian dt = new DateTimePersian(); string shamsiDate = dt.shamsiDate(); using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>()) { // singleOrDefualt() اولین درخواست با این مشخصات دیدی بهم تحویل بده var query = (from br in db.borrowBooks where br.BorrowId == id select br); var result = query.SingleOrDefault(); // کم کردن موجودی var findBook = (from b in db.books where b.BookId == result.BookId select b); var resultBook = findBook.SingleOrDefault(); if (findBook.Count() != 0) { resultBook.BookStock--; db.books.Attach(resultBook); db.Entry(resultBook).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } // به مانت بردن if (query.Count() != 0) { result.Flag = 2; result.DateTimeConfirmAdmin = shamsiDate; db.borrowBooks.Attach(result); db.Entry(result).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); } } }
public void RejectRequestConfirm(int id) { using (var db = _iServiceProvider.GetRequiredService <ApplicationDbContext>()) { //// تاریخ شمسی DateTimePersian dt = new DateTimePersian(); string shamsiDate = dt.shamsiDate(); using (var transaction = db.Database.BeginTransaction()) { // singleOrDefualt() اولین درخواست با این مشخصات دیدی بهم تحویل بده var query = (from br in db.borrowBooks where br.BorrowId == id select br); var result = query.SingleOrDefault(); if (query.Count() != 0) { result.Flag = 3; result.DateTimeConfirmAdmin = shamsiDate; db.borrowBooks.Attach(result); db.Entry(result).State = Microsoft.EntityFrameworkCore.EntityState.Modified; // برگشت مبلغ به کیف کاربر var query_back_money = (from u in db.Users where u.Id == result.UserId select u).SingleOrDefault(); query_back_money.Wallet += result.Price; } db.SaveChanges(); transaction.Commit(); } } }
public IActionResult BookRequest(string UserId) { if (_signInManager.IsSignedIn(User)) { // get name of user string UserId_ = _ius.GetId(); ViewBag.fullname = _ius.GetById(UserId_).FirstName + " " + _ius.GetById(UserId_).LastName; // update wallet ViewBag.Wallet = _ius.GetById(UserId_).Wallet; } // -1. check total price is lower wallet of User // 0. check request befor (prevent repeat) // 1. save in data base // 2. clear cookies //string UserID = _userManager.GetUserId(HttpContext.User); string cookieContent = Request.Cookies["_gharz"].ToString(); string[] listShop = cookieContent.Split(",").Where(r => r != "").ToArray(); var model = new MultiModels(); // step: -1 if (Request.Cookies["_gharz"] != null) { // query to sql model.listShop = _ibs.GetByIdRange(listShop); } long totalPrice = model.listShop.Sum(b => b.Price); string userid_ = _ius.GetId(); long wallet_user = _ius.GetById(userid_).Wallet; if (totalPrice > wallet_user) { return(Json(new { status = "fail", message = "موجودی شما کافی نیست" })); } // step: 0 if (Request.Cookies["_gharz"] != null) { var query = _ibs.BorrowCheck(_ius.GetId(), listShop); if (query.Count() > 0) { return(Json(new { status = "exist", message = "لیست شامل کتابی است که قبلا درخواست داده اید" })); } } // step: 1 // استفاده از ترنزکشن _ibs.saveBorrow(listShop, userid_, dtPersian.shamsiDate(), totalPrice); // step: 2 Response.Cookies.Delete("_gharz"); return(Json(new { status = "success", message = "ثبت شد و منتظر تایید نهایی باید" })); //} }
public async Task <IActionResult> PaymentVerify(int amount, string description, string email, string mobile, string Authority, string Status) { if (_signInManager.IsSignedIn(User)) { // get name of user string UserId = _ius.GetId(); ViewBag.fullname = _ius.GetById(UserId).FirstName + " " + _ius.GetById(UserId).LastName; // update wallet ViewBag.Wallet = _ius.GetById(UserId).Wallet; } if (Status == "NOK") { return(View("failedPayment")); } // ارسال به صفحه خطا var verification = await new ZarinpalSandbox.Payment(amount).Verification(Authority); // ارسال کد تراکنش جهت نمایش به کاربر if (verification.Status != 100) { return(View("failedView")); } // اطلاعات پرداخت var RefId = verification.RefId; // اگر اطلاعات درست باشد، باید در دیتابیس ذخیره شود ------------ DateTimePersian dt = new DateTimePersian(); string shamsiDate = dt.shamsiDate(); string shamsiTime = dt.shamsiTime(); // ثبت اطلاعات پرداخت در دیتابیس var result = _ips.PaymentVerify(_ius.GetId(), email, mobile, description, amount, verification.RefId.ToString()); if (result) { ViewBag.TransactionNo = verification.RefId.ToString(); ViewBag.TransactonDate = shamsiDate; ViewBag.TransactionTime = shamsiTime; ViewBag.Description = description; ViewBag.Amount = amount; return(View("SuccessfullyPayment")); } else { return(View("failedPayment")); } }
public IActionResult AddEditNews(int id) { var model = new News(); ViewBag.RootPath = "/upload/thumbnailnews/"; if (id != 0) { model = _ins.FindById(id); if (model == null) { return(RedirectToAction("Index")); } } DateTimePersian dt = new DateTimePersian(); ViewBag.sdate = dt.shamsiDate(); return(PartialView("_AddEditnews", model)); }