示例#1
0
        public async Task <ServiceResult> DeleteAsync(RentHistory entity)
        {
            var result = new ServiceResult(false);

            try
            {
                var rent = await unitOfWork.Rents.GetAsync(a => a.RentID == entity.RentID);

                if (rent == null)
                {
                    throw new NullReferenceException("Kira bilgisine ulaşılamityor!");
                }
                var datedif = DateTime.Now - rent.CreatedDate;
                if (datedif.TotalHours > 24)
                {
                    throw new Exception("Kira kayıdı eklendiği zamandan sadece 24 saat sonraya kadar silinebilir");
                }
                unitOfWork.Rents.Delete(rent);
                result.isSuccess = await unitOfWork.SaveChangesAsync() > 0;

                if (result.isSuccess)
                {
                    result.Errors.Add("Kira kaydı başarıyla silindi");
                }
                else
                {
                    result.Errors.Add("Kira kaydı silinemedi");
                }
            }
            catch (Exception ex)
            {
                result.Errors.Add(ex.Message);
            }
            return(result);
        }
        public ActionResult RentSuccessful(int id)
        {
            RentHistory rent = db.RentHistory.Find(id);

            ViewBag.Movie = db.Movies.Find(rent.MovieId);
            return(View(rent));
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            RentHistory rentHistory = db.RentHistories.Find(id);

            db.RentHistories.Remove(rentHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        public static async Task <ConnectorResponseModel> GetRentDues(UserModel user)
        {
            RentHistory objRentH = HttpClientRQHandler.SendRQ <RentHistory, UserModel>(user, "/GetInvoices");

            if (!(objRentH is RentHistory && objRentH.ResponseStatus.ResponseCode == (int)ResponseCode.Success))
            {
                objRentH = null;
            }
            return(await Task.FromResult(objRentH));
        }
 public ActionResult Edit([Bind(Include = "ID,NegotiatedOn,Details")] RentHistory rentHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rentHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "RentHistorise", new { id = rentHistory.AssetID }));
     }
     return(View(rentHistory));
 }
示例#6
0
        public async Task <ServiceResult> AddAsync(RentHistory entity)
        {
            var result = new ServiceResult();

            try
            {
                if (!await unitOfWork.Users.AnyExistAsync(a => a.UserID == entity.UserID))
                {
                    throw new Exception("Yetkili bilgilerine ulaşılamiyor!");
                }

                var member = await unitOfWork.Members.GetAsync(a => a.MemberID == entity.MemberID);

                if (member == null)
                {
                    result.Errors.Add("Üye bulunamadı!");
                }
                else if (member.AwaableToRent == false || member.RemainedRentConut < 1)
                {
                    result.Errors.Add("Üye kiralama için uygun değil!");
                }

                var book = await unitOfWork.Books.GetAsync(a => a.BookID == entity.BookID);

                if (book == null)
                {
                    result.Errors.Add("Kitap bulanamadı");
                }
                else if (book.AvailableQuantity < 1)
                {
                    result.Errors.Add("Seçilen kitap kıralama inin uygun değil!");
                }

                if (result.Errors.Count() == 0)
                {
                    member.RemainedRentConut -= 1;
                    book.AvailableQuantity   -= 1;
                    unitOfWork.Rents.Add(entity);
                    unitOfWork.Books.Update(book);
                    unitOfWork.Members.Update(member);
                    if (await unitOfWork.SaveChangesAsync() > 0)
                    {
                        result.isSuccess = true;
                        result.Errors.Add("Kira kaydı başarıyla tamamlandı!");
                    }
                }
            }
            catch (Exception ex)
            {
                result.isSuccess = false;
                result.Errors.Add(ex.Message);
            }
            return(result);
        }
        public ActionResult Create([Bind(Include = "ID,NegotiatedOn,Details")] RentHistory rentHistory)
        {
            if (ModelState.IsValid)
            {
                rentHistory.ID = Guid.NewGuid();
                db.RentHistories.Add(rentHistory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rentHistory));
        }
示例#8
0
 public ActionResult Edit([Bind(Include = "Id,MovieId,UserId,RentDate,RentTime")] RentHistory rentHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rentHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MovieId = new SelectList(db.Movies, "Id", "UserId", rentHistory.MovieId);
     ViewBag.UserId  = new SelectList(db.Users, "Id", "Email", rentHistory.UserId);
     return(View(rentHistory));
 }
示例#9
0
        public void StartRent(string scooterId)
        {
            var scooter = ScooterService.GetScooterById(scooterId);

            if (scooter.IsRented)
            {
                throw new ScooterIsRented("The scooter is being rented.");
            }

            scooter.IsRented = true;
            RentHistory.Add(new RentedUnit(_transId++, scooterId, DateTime.Now, scooter.PricePerMinute));
        }
        // GET: RentHistories/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentHistory rentHistory = db.RentHistories.Find(id);

            if (rentHistory == null)
            {
                return(HttpNotFound());
            }
            return(View(rentHistory));
        }
示例#11
0
        public ActionResult Create([Bind(Include = "Id,MovieId,UserId,RentDate,RentTime")] RentHistory rentHistory)
        {
            if (ModelState.IsValid)
            {
                DateTime localDate = DateTime.Now;
                rentHistory.RentDate = localDate;
                db.RentHistory.Add(rentHistory);
                db.SaveChanges();
                return(RedirectToAction("RentSuccessful", "Movies", new { id = rentHistory.Id }));
            }

            ViewBag.MovieId = new SelectList(db.Movies, "Id", "UserId", rentHistory.MovieId);
            ViewBag.UserId  = new SelectList(db.Users, "Id", "Email", rentHistory.UserId);
            return(View(rentHistory));
        }
示例#12
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentHistory rentHistory = db.RentHistory.Find(id);

            if (rentHistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MovieId = new SelectList(db.Movies, "Id", "UserId", rentHistory.MovieId);
            ViewBag.UserId  = new SelectList(db.Users, "Id", "Email", rentHistory.UserId);
            return(View(rentHistory));
        }
示例#13
0
        public async Task <ActionResult> RetrieveDueInvoices()
        {
            UserModel   objUser     = Session[SessionConstants.UserSession] as UserModel;
            RentHistory objInvoices = await Connector.GetRentDues(objUser) as RentHistory;

            List <Invoicesdata> lsInvoices = new List <Invoicesdata>();

            if (objInvoices != null && objInvoices.Result != null && objInvoices.Result.InvoicesData != null)
            {
                lsInvoices = objInvoices.Result.InvoicesData.ToList();
            }
            return(Json(new ResponseModel()
            {
                Status = false, Data = lsInvoices, Errors = null
            }, JsonRequestBehavior.AllowGet));
        }
示例#14
0
        public async Task <ServiceResult> UpdateAsync(RentHistory entity)
        {
            var result = new ServiceResult();

            try
            {
                unitOfWork.Rents.Update(entity);
                await unitOfWork.SaveChangesAsync();

                result.Errors.Add("Kira güncellendi");
                result.isSuccess = true;
            }
            catch (Exception ex)
            {
                result.Errors.Add(ex.Message);
            }
            return(result);
        }
示例#15
0
        public static async Task <ConnectorResponseModel> Authenticate(UserModel user)
        {
            UserModel objUser = new UserModel();

            RentHistory objRentRsp = HttpClientRQHandler.SendRQ <RentHistory, UserModel>(user, "/GetInvoices");

            if (objRentRsp is RentHistory && objRentRsp.ResponseStatus.ResponseCode == (int)ResponseCode.Success)
            {
                objUser = new UserModel()
                {
                    UserName   = user.UserName,
                    Password   = user.Password,
                    CardCode   = objRentRsp.Result.InvoicesData != null && objRentRsp.Result.InvoicesData.Count() > 0 ? objRentRsp.Result.InvoicesData.First().CardCode : string.Empty,
                    CardName   = objRentRsp.Result.InvoicesData != null && objRentRsp.Result.InvoicesData.Count() > 0 ? objRentRsp.Result.InvoicesData.First().CardName : string.Empty,
                    IsLoggedIn = true
                };
            }

            return(await Task.FromResult(objUser));
        }
示例#16
0
        public ActionResult Edit(Asset asset, FullAddress fullAddress)
        {
            if (ModelState.IsValid)
            {
                asset.Address         = fullAddress;
                db.Entry(asset).State = EntityState.Modified;

                if (Session["Rent"] != asset.AskingRent)
                {
                    RentHistory rentHistory = new RentHistory();
                    rentHistory.ID           = Guid.NewGuid();
                    rentHistory.Asset        = asset;
                    rentHistory.Details      = "Rent : " + asset.AskingRent;
                    rentHistory.NegotiatedOn = DateTime.Now;
                    db.RentHistories.Add(rentHistory);
                }
                db.SaveChanges();

                Session.Remove("Rent");
                return(RedirectToAction("Index", new { customerID = Session["customerID"] }));
            }
            return(View(asset));
        }
示例#17
0
        public ActionResult Create(Asset asset, FullAddress fullAddress)
        {
            if (ModelState.IsValid)
            {
                fullAddress.ID = Guid.NewGuid();
                asset.Address  = fullAddress;

                asset.AssetID = Guid.NewGuid();
                db.Assets.Add(asset);

                RentHistory rentHistory = new RentHistory();
                rentHistory.ID           = Guid.NewGuid();
                rentHistory.AssetID      = asset.AssetID;
                rentHistory.Details      = "Rent : " + asset.AskingRent;
                rentHistory.NegotiatedOn = DateTime.Now;
                db.RentHistories.Add(rentHistory);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(asset));
        }
示例#18
0
        public async Task <IActionResult> New(AddNewRentModel model)
        {
            if (ModelState.IsValid)
            {
                var rentStartDate = new DateTime(model.StartYear, model.StartMonth, model.StartDay);
                var rentEndDate   = rentStartDate.AddDays(model.RentDayCount);

                var cliemUserID = User.Claims.FirstOrDefault(a => a.Type.Equals("UserID"));
                var userID      = int.Parse(cliemUserID.Value.ToString());

                var rent = new RentHistory()
                {
                    BookID          = model.BookID,
                    CreatedDate     = DateTime.Now,
                    LastUpdatedDate = DateTime.Now,
                    isDelayed       = false,
                    MemberID        = model.MemberID,
                    RentDate        = rentStartDate,
                    RentEndDate     = rentEndDate,
                    DelayedDayCount = 0,
                    UserID          = userID,
                    DelayFine       = 0,
                };

                var result = await rentService.AddAsync(rent);

                if (result.isSuccess)
                {
                    return(RedirectToAction("Index"));
                }
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError("", item);
                }
            }
            return(View(model));
        }
示例#19
0
        public async Task <ActionResult> RetrieveClubbedInvoices(int dueInv, int paidInv, int maxCount)
        {
            List <InvoiceGeneralModel> lsClubbedInvoices = new List <InvoiceGeneralModel>();

            List <Task>         lsTsk          = new List <Task>();
            UserModel           objUser        = Session[SessionConstants.UserSession] as UserModel;
            List <Invoicesdata> lsDueInvoices  = new List <Invoicesdata>();
            List <PaidInvoices> lsPaidInvoices = new List <PaidInvoices>();
            Task dueTask = await Task.Factory.StartNew(async() =>
            {
                RentHistory objInvoices = await Connector.GetRentDues(objUser) as RentHistory;
                if (objInvoices != null && objInvoices.Result != null && objInvoices.Result.InvoicesData != null)
                {
                    lsDueInvoices = objInvoices.Result.InvoicesData.ToList();
                }
            }, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

            Task paidTask = await Task.Factory.StartNew(async() =>
            {
                PaidRentHistory objInvoices = await Connector.GetRentHistory(objUser) as PaidRentHistory;
                if (objInvoices != null && objInvoices.Result != null && objInvoices.Result.InvoicesData != null)
                {
                    lsPaidInvoices = objInvoices.Result.InvoicesData.ToList();
                }
            }, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

            lsTsk.Add(dueTask);
            lsTsk.Add(paidTask);

            await Task.WhenAll(lsTsk.ToArray());

            if (lsDueInvoices is List <Invoicesdata> )
            {
                dueInv = dueInv == 0 ? lsDueInvoices.Count : lsDueInvoices.Count > dueInv ? lsDueInvoices.Count : lsDueInvoices.Count;
                for (int invCnt = 0; invCnt < lsDueInvoices.Count; invCnt++)
                {
                    lsClubbedInvoices.Add(new InvoiceGeneralModel()
                    {
                        BranchID        = "",
                        DocEntryNo      = lsDueInvoices[invCnt].DocEntryNo,
                        InvoiceMonth    = lsDueInvoices[invCnt].strDocMonth,
                        DocTotal        = lsDueInvoices[invCnt].DocTotal,
                        InvoiceCurrency = "KWD",
                        InvoiceDate     = lsDueInvoices[invCnt].strDocDate,
                        InvoiceDueDate  = lsDueInvoices[invCnt].strDueDate,
                        InvoiceFine     = "0",
                        IsPaid          = false
                    });
                }
            }
            if (lsPaidInvoices is List <PaidInvoices> )
            {
                paidInv = paidInv == 0 ? lsPaidInvoices.Count : lsPaidInvoices.Count > paidInv ? lsPaidInvoices.Count : lsPaidInvoices.Count;
                for (int invCnt = 0; invCnt < lsPaidInvoices.Count; invCnt++)
                {
                    lsClubbedInvoices.Add(new InvoiceGeneralModel()
                    {
                        BranchID        = "",
                        DocEntryNo      = lsPaidInvoices[invCnt].IPDocNum,
                        InvoiceMonth    = lsPaidInvoices[invCnt].strDocMonth,
                        DocTotal        = lsPaidInvoices[invCnt].InvPaidAmount.ToString(),
                        InvoiceCurrency = "KWD",
                        InvoiceDate     = lsPaidInvoices[invCnt].strDocDate,
                        InvoiceFine     = "0",
                        IsPaid          = true,
                        Payment         = new InvoicePayment()
                        {
                            InvReffNo = lsPaidInvoices[invCnt].PayRefNo,
                            PayID     = lsPaidInvoices[invCnt].PayID,
                            PayReff   = lsPaidInvoices[invCnt].RefNo
                        }
                    });
                }
            }

            maxCount = maxCount == 0 ? lsClubbedInvoices.Count : maxCount;

            return(Json(new ResponseModel()
            {
                Status = false, Data = lsClubbedInvoices.Take(maxCount), Errors = null
            }, JsonRequestBehavior.AllowGet));
        }
示例#20
0
        public void RentItem(int bookId, string CardId)
        {
            var card = _context.RentCards
                       .FirstOrDefault(c => c.CardId == CardId);

            if (card != null)
            {
                var now  = DateTime.Now;
                var book = _context.Textbooks
                           .Include(tx => tx.Status)
                           .FirstOrDefault(tx => tx.Id == bookId);

                var renter = _context.Renters
                             .FirstOrDefault(r => r.RentCard.Id == card.Id);

                var totalCp = book.NumberOfCopies;
                var rentCp  = book.NumberOfRentOuts;

                if (totalCp > rentCp)
                {
                    _context.Update(book);
                    book.NumberOfRentOuts += 1;

                    rentCp += 1;

                    if (rentCp == totalCp)
                    {
                        if (!CurrentHold(bookId).Any())
                        {
                            UpdateTXStatus(bookId, "All Out");
                        }
                        else
                        {
                            UpdateTXStatus(bookId, "On Hold");
                        }
                    }
                    else
                    {
                        if (book.Status.Name == "All In")
                        {
                            UpdateTXStatus(bookId, "Rent Out");
                        }
                    }

                    var rent = new Rent
                    {
                        Textbook = book,
                        RentCard = card,
                        Since    = now,
                        Until    = GetDefaultRentTime(now)
                    };

                    _context.Add(rent);

                    var rentHistory = new RentHistory
                    {
                        RentedOut = now,
                        Textbook  = book,
                        Renter    = renter,
                    };

                    _context.Add(rentHistory);
                    _context.SaveChanges();
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }
        }