예제 #1
0
        public RentModel CancelRentVehicle(RentModel rentModel)
        {
            RentModel rent = null;

            try
            {
                VehicleRepository vehicleRepository = new VehicleRepository();
                Vehicle           vehicle           = vehicleRepository.SelectedByNumber(rentModel.vehiclenumber);

                if (vehicle == null)
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Vehcile Is Not Found! \n");
                }

                //Rent Update
                RentRepository rentRepository = new RentRepository();

                rentModel.isactive = 0;
                rentRepository.Update(rentModel);

                rent = rentRepository.SelectedByVehicleAndMember(rentModel.vehiclenumber, rentModel.membernumber);

                //Vehicle Update
                vehicle.istaken = 0;
                vehicleRepository.Update(vehicle);
            }
            catch (Exception ex)
            {
                throw new Exception("CustomerBisuness::RentVehicle: Error occured.\n", ex);
            }
            return(rent);
        }
예제 #2
0
        public IActionResult StartRent([FromBody] RentModel rm)
        {
            Rent r = appCtx.Rents.FirstOrDefault(s => s.BikeId == rm.BikeId && s.EndTime == null);

            if (r == null)
            {
                Bike b    = appCtx.Bikes.FirstOrDefault(b => b.Id == rm.BikeId);
                User user = (User)HttpContext.Items["User"];
                if (b != null)
                {
                    Rent rent = new Rent
                    {
                        BikeId    = rm.BikeId,
                        Bike      = b,
                        UserId    = user.Id,
                        User      = user,
                        StartTime = DateTime.Now
                    };
                    appCtx.Rents.Add(rent);
                    appCtx.SaveChanges();
                    return(Ok());
                }
            }
            return(BadRequest());
        }
예제 #3
0
        public async Task <IActionResult> EndRent([FromBody] RentModel rm)
        {
            User   user      = (User)HttpContext.Items["User"];
            Rent   rent      = appCtx.Rents.Include(r => r.Bike).Include(r => r.User).Where(r => r.BikeId == rm.BikeId && r.EndTime == null).FirstOrDefault();
            long   dateticks = DateTime.Now.Ticks;
            Random random    = new Random();
            Day    day       = new Day()
            {
                Date         = (long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds,
                Km           = random.Next(5, 15),
                StatisticsId = (int)user.StatisticsId
            };

            appCtx.Days.Add(day);
            if (rent != null)
            {
                rent.EndTime             = DateTime.Now;
                appCtx.Entry(rent).State = EntityState.Modified;
                appCtx.SaveChanges();
                await LiqPay(user, rent);

                return(Ok());
            }
            return(BadRequest());
        }
예제 #4
0
        public void Update(RentModel rent)
        {
            VerifyDiscount(rent);
            CalculateReturnDate(rent);

            RentData.Update(rent);
        }
        /// <summary>
        /// set a new rent to the DB
        /// </summary>
        /// <param name="newrentparam">a rent model object</param>
        /// <returns>true if the actions secseed false if it didnt</returns>
        public static bool AddNewRent(RentModel newrentparam)
        {
            try
            {
                using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
                {
                    UsersTable dbUser = db.UsersTables.FirstOrDefault(a => a.UserName == newrentparam.UserInfo.UserName);
                    CarsTable  dbCar  = db.CarsTables.FirstOrDefault(a => a.CarlicenseNumber == newrentparam.CarInfo.CarlicenseNumber);
                    if (dbUser == null || dbCar == null)
                    {
                        return(false);
                    }
                    RentTable NewRent = new RentTable
                    {
                        StartDate  = newrentparam.StartDate,
                        EndDate    = newrentparam.EndDate,
                        ReturnDate = newrentparam.ReturnDate,
                        UserID     = dbUser.ID,
                        CarID      = dbCar.ID
                    };

                    db.RentTables.Add(NewRent);
                    db.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
예제 #6
0
        public ActionResult Rent(RentModel formModel)
        {
            RentModel model = new RentModel();

            DateTime ds = formModel.DateStart;
            DateTime df = formModel.DateFinish;

            bool   cr  = formModel.request.ClassRoom;
            string idS = formModel.GrIdStr;
            int    id  = Int32.Parse(idS);
            int    si  = formModel.request.GrSize;
            bool   wh  = formModel.request.Whiteboard;
            bool   mon = formModel.request.Monitor;
            bool   pr  = formModel.request.Projector;

            //Saves session cookie if they want classroom
            Session["cr"] = cr;
            //Saves session cookie: GroupId
            Session["id"] = id;
            //Saves session cookie: GroupSize
            Session["si"] = si;
            //Saves session cookie: start/finish date
            Session["ds"] = ds;
            Session["df"] = df;
            //Saves session cookie: preferences about whiteboard, monitor and projector(classroom only)
            Session["wh"]  = wh;
            Session["mon"] = mon;
            Session["pr"]  = pr;

            return(Redirect("Grouproom"));
        }
예제 #7
0
        public async Task <int> RentCar(RentModel model)
        {
            try
            {
                var carRentId = await _rentRepository.RentCar(new Data.Rents()
                {
                    CarNumber     = model.CarNumber,
                    CreatedDate   = model.CreatedDate,
                    RentPrice     = model.RentPrice,
                    Staus         = model.Staus,
                    TransactionId = model.TransactionId
                });

                _carEventProducer.SendOrderDoneMessage(new CarOrderConfirmedMessage()
                {
                    TransactionId = model.TransactionId,
                    CarRentId     = carRentId
                });
                // throw  new Exception();
                return(carRentId);
            }
            catch (Exception e)
            {
                _carEventProducer.SendOrderNotCompleterdMessage(model.TransactionId);
                Console.WriteLine(e);
                return(-1);
            }
        }
예제 #8
0
        public ActionResult Admin(int rentId, int res)
        {
            HttpResponseMessage response = client.GetAsync("api/rents/" + rentId).Result;
            Rentalinformation   rent     = response.Content.ReadAsAsync <Rentalinformation>().Result;

            if (res == 1)
            {
                Rentalinformation tempRent = new Rentalinformation()
                {
                    CustomerID  = rent.CustomerID,
                    VehicleID   = rent.VehicleID,
                    HowManyDays = rent.HowManyDays,
                    Id          = rent.Id,
                    IsRequest   = rent.IsRequest,
                    IsActive    = rent.IsActive,
                    LastKmId    = rent.LastKmId,
                    Payment     = rent.Payment,
                    StartKm     = rent.StartKm
                };

                RentModel model = new RentModel();
                model.rent       = tempRent;
                model.vehicleId  = rent.VehicleID;
                model.customerId = rent.CustomerID;

                //kirala
                response = client.PostAsJsonAsync("api/vehicles/RentACar", model).Result;
            }
            else if (res == 0)
            {
                response = client.GetAsync("api/vehicles/UnRentACar?id=" + rent.Id).Result;
            }

            return(Redirect("/Login/Admin"));
        }
 /// <summary>
 /// edit a rent acording to a rent id sent by the cient
 /// </summary>
 /// <param name="RentId">the rent id sent by the client</param>
 /// <param name="rentparam">a rent model contains all the rent data</param>
 /// <returns>true if the actions secseed false if it didnt</returns>
 public static bool EditRent(int RentId, RentModel rentparam)
 {
     try
     {
         using (CarRentalDbV2Entities db = new CarRentalDbV2Entities())
         {
             RentTable  dbrent = db.RentTables.SingleOrDefault(a => a.ID == RentId);
             UsersTable dbuser = db.UsersTables.SingleOrDefault(a => a.UserName == rentparam.UserInfo.UserName);
             CarsTable  dbcar  = db.CarsTables.SingleOrDefault(a => a.CarlicenseNumber == rentparam.CarInfo.CarlicenseNumber);
             if (dbrent == null || dbuser == null || dbcar == null)
             {
                 return(false);
             }
             dbrent.CarID      = dbcar.ID;
             dbrent.UserID     = dbuser.ID;
             dbrent.EndDate    = rentparam.EndDate;
             dbrent.ReturnDate = rentparam.ReturnDate;
             dbrent.StartDate  = rentparam.StartDate;
             db.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
예제 #10
0
        public void Get_CallsGetFromRentData_ReturnsRentModel()
        {
            mocker.Setup(o => o.Get(id)).Returns(rentModelWithId);
            IRentBusiness sut = GetSut();

            RentModel rent = sut.Get(id);

            Assert.AreSame(rentModelWithId, rent);
        }
 public IActionResult GetAllAvailableCarTypes(RentModel rentModel)
 {
     try
     {
         return(Ok(carTypesLogic.GetAllAvailableCarTypes(rentModel)));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
예제 #12
0
 public void Post([FromBody] RentModel value)
 {
     try
     {
         _rentCarService.RentCar(value);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
예제 #13
0
 public IActionResult RentFirstCarAvailable(int CarTypeId, RentModel rentModel)
 {
     try
     {
         return(Ok(rentsLogic.RentFirstCarAvailable(CarTypeId, rentModel)));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
예제 #14
0
        private void VerifyDiscount(RentModel rent)
        {
            decimal discount = 1;

            if (rent.Bicycles >= 3)
            {
                discount = 0.7M;
            }

            rent.Price = rent.Cost * rent.Count * rent.Bicycles * discount;
        }
예제 #15
0
 public IActionResult ReturnCar(int rentId, RentModel rentModel)
 {
     try
     {
         return(Ok(rentsLogic.ReturnCar(rentId, rentModel)));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
예제 #16
0
 public IActionResult GetAllAvailableCars(RentModel rentModel)
 {
     try
     {
         List <CarModel> availableCars = carsLogic.GetAllAvailableCars(rentModel);
         return(Ok(availableCars));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
예제 #17
0
        public ActionResult Create(RentModel rent)
        {
            try
            {
                RentBusiness.Create(rent);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #18
0
        public HttpResponseMessage Get(int RentIdParam)
        {
            RentModel SingleRent = RentManager.GetSpesificRent(RentIdParam);

            if (SingleRent == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ObjectContent <RentModel>(SingleRent, new JsonMediaTypeFormatter())
            });
        }
예제 #19
0
        public HttpResponseMessage Put(int RentIdParam, [FromBody] RentModel rentparam)
        {
            bool updateResult = false;

            if (ModelState.IsValid)
            {
                updateResult = RentManager.EditRent(RentIdParam, rentparam);
            }
            HttpStatusCode rsponseCode = (updateResult) ? HttpStatusCode.OK : HttpStatusCode.BadRequest;

            return(new HttpResponseMessage(rsponseCode)
            {
                Content = new ObjectContent <bool>(updateResult, new JsonMediaTypeFormatter())
            });
        }
예제 #20
0
        public HttpResponseMessage Post([FromBody] RentModel value)
        {
            bool InsertResult = false;

            if (ModelState.IsValid)
            {
                InsertResult = RentManager.AddNewRent(value);
            }
            HttpStatusCode ResponsCode = InsertResult ? HttpStatusCode.Created : HttpStatusCode.BadRequest;

            return(new HttpResponseMessage(ResponsCode)
            {
                Content = new ObjectContent <bool>(InsertResult, new JsonMediaTypeFormatter())
            });
        }
예제 #21
0
        private DateTime CalculateReturnDate(RentModel rent)
        {
            switch ((RentType)rent.Cost)
            {
            case RentType.hours:
                return(rent.Date.AddHours(rent.Count));

            case RentType.days:
                return(rent.Date.AddDays(rent.Count));

            case RentType.weeks:
                return(rent.Date.AddDays(rent.Count * 7));
            }

            return(DateTime.Now);
        }
        public async Task <IActionResult> OnPostTariffAsync(int?holderId, string tariff, string card)
        {
            IdentifyCostumer();
            if (!IsAuthorized())
            {
                return(JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "Not Authorized"));
            }
            if (holderId == null)
            {
                return(JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "Wrong Data"));
            }

            var _holder = await _appRepository.Holders.Include(x => x.HolderRentModels).ThenInclude(x => x.RentModel).FirstOrDefaultAsync(x => x.Id == holderId);

            RentModel rentModel = null;

            switch (tariff)
            {
            case "hour":
                rentModel = _holder.HolderRentModels.FirstOrDefault(x => x.RentModel.RentStrategy == RentStrategy.Hour).RentModel;
                break;

            case "day":
                rentModel = _holder.HolderRentModels.FirstOrDefault(x => x.RentModel.RentStrategy == RentStrategy.Day).RentModel;
                break;

            case "firstHourFree":
                rentModel = _holder.HolderRentModels.FirstOrDefault(x => x.RentModel.RentStrategy == RentStrategy.FirstHourFree).RentModel;
                break;

            default:
                break;
            }

            if (rentModel == null)
            {
                return(JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpClientErrorCode, "No such rent model"));
            }

            var result = await _holderService.ProvidePowerBank(Costumer.Id, holderId ?? 0, rentModel, card);

            if (!result)
            {
                return(JsonHelper.JsonResponse(Strings.StatusError, Constants.HttpServerErrorCode, "Can't provide powerbank"));
            }
            return(JsonHelper.JsonResponse(Strings.StatusOK, Constants.HttpOkCode));
        }
예제 #23
0
        private void CalculateReturnDate(RentModel rent)
        {
            switch ((RentType)rent.Cost)
            {
            case RentType.hours:
                rent.ReturnDate = rent.Date.AddHours(rent.Count);
                break;

            case RentType.days:
                rent.ReturnDate = rent.Date.AddDays(rent.Count);
                break;

            case RentType.weeks:
                rent.ReturnDate = rent.Date.AddDays(rent.Count * 7);
                break;
            }
        }
예제 #24
0
        public void Create_WithWeeksCost_CalculateReturnDate()
        {
            RentModel rentModel = new RentModel
            {
                Bicycles = 3,
                Cost     = weekCost,
                Count    = 1,
                Date     = DateTime.Now
            };

            mocker.Setup(o => o.Create(rentModel));
            IRentBusiness sut = GetSut();

            sut.Create(rentModel);

            Assert.AreEqual(CalculateReturnDate(rentModel), rentModel.ReturnDate);
        }
예제 #25
0
        public void Create_WithDiscount_VerifyDiscount()
        {
            RentModel rentModel = new RentModel
            {
                Bicycles = 3,
                Cost     = hourCost,
                Count    = 1,
                Date     = DateTime.Now
            };

            mocker.Setup(o => o.Create(rentModel));
            IRentBusiness sut = GetSut();

            sut.Create(rentModel);

            Assert.AreEqual(DoDiscount(rentModel), rentModel.Price);
        }
예제 #26
0
        public IActionResult Edit(RentModel rml)
        {
            var rent = _service.Get(x => x.RentID == rml.RentID);

            rent.CompanyID         = rml.CompanyID;
            rent.CustomerID        = rml.CustomerID;
            rent.DamagePrice       = rml.DamagePrice;
            rent.DelayFine         = rml.DelayFine;
            rent.RentBranchID      = rml.RentBranchID;
            rent.DeliveredBranchID = rml.BranchID;
            rent.TotalRentPrice    = rml.TotalRentPrice;
            rent.UserID            = rml.UserID;
            rent.CarID             = rml.CarID;
            rent.RentStartDate     = DateTime.UtcNow;
            rent.RentEndDate       = DateTime.FromFileTime(11111995);
            _service.Update(rent);
            return(RedirectToAction("Index"));
        }
예제 #27
0
        public void Update_WithoutDiscount_VerifyNoDiscount()
        {
            RentModel rentModel = new RentModel
            {
                Id       = id,
                Bicycles = 1,
                Cost     = hourCost,
                Count    = 1,
                Date     = DateTime.Now
            };

            mocker.Setup(o => o.Update(rentModel));
            IRentBusiness sut = GetSut();

            sut.Update(rentModel);

            Assert.AreEqual(DoNotDiscount(rentModel), rentModel.Price);
        }
예제 #28
0
        public void Update_WithDateTimeNow_CalculateReturnDate()
        {
            RentModel rentModel = new RentModel
            {
                Id       = id,
                Bicycles = 3,
                Cost     = hourCost,
                Count    = 1,
                Date     = DateTime.Now
            };

            mocker.Setup(o => o.Update(rentModel));
            IRentBusiness sut = GetSut();

            sut.Update(rentModel);

            Assert.AreEqual(CalculateReturnDate(rentModel), rentModel.ReturnDate);
        }
예제 #29
0
        public RentModel RentVehicle(RentModel rentModel)
        {
            RentModel rent = null;

            try
            {
                VehicleRepository vehicleRepository = new VehicleRepository();
                Vehicle           vehicle           = vehicleRepository.SelectedByNumber(rentModel.vehiclenumber);

                if (vehicle == null)
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Vehcile Is Not Found! \n");
                }

                MemberRepository repository   = new MemberRepository();
                Member           isHaveMember = repository.SelectedByNumber(rentModel.membernumber);

                if (isHaveMember == null)
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Customer Is Not Found! \n");
                }

                if (vehicleRepository.VehicleIsTaken(rentModel.vehiclenumber))
                {
                    throw new Exception("CustomerBisuness::RentVehicle: Vehicle Is Not Available! \n");
                }

                RentRepository rentRepository = new RentRepository();
                rentRepository.Insert(rentModel);
                rent = rentRepository.SelectedByVehicleAndMember(rentModel.vehiclenumber, rentModel.membernumber);

                //Vehicle Update
                vehicle.istaken = 1;
                vehicleRepository.Update(vehicle);
            }
            catch (Exception ex)
            {
                throw new Exception("CustomerBisuness::RentVehicle: Error occured.\n", ex);
            }
            return(rent);
        }
 public ActionResult Edit([Bind(Include = "rentId,renterId,equipmentId,rentTimeStart,rentTimeEnd,rentName,rentDescription")] RentModel rentingEquipment)
 {
     if (ModelState.IsValid)
     {
         var edited = new RentingEquipment
         {
             rentId          = rentingEquipment.renterId,
             renterId        = rentingEquipment.renterId,
             equipmentId     = rentingEquipment.equipmentId,
             rentName        = rentingEquipment.rentName,
             rentTimeStart   = rentingEquipment.rentTimeStart,
             rentTimeEnd     = rentingEquipment.rentTimeEnd,
             rentDescription = rentingEquipment.rentDescription
         };
         db.Entry(edited).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.equipmentId = new SelectList(db.SailingEquipment, "equipmentId", "equipmentName", rentingEquipment.equipmentId);
     ViewBag.renterId    = new SelectList(db.Users, "userId", "userName", rentingEquipment.renterId);
     return(View(rentingEquipment));
 }