Exemple #1
0
        public rent GetDbObjectOnCreate(string username, Guid idOwner)
        {
            rent dbItem = new rent
            {
                cancel_notes    = CancelNotes,
                code            = Code,
                created_by      = username,
                created_time    = DateTimeOffset.Now,
                finish_rent     = FinishRent,
                id_car          = IdCar,
                id_car_model    = IdCarModel.Value,
                id_customer     = IdCustomer.Value,
                id_driver       = IdDriver,
                id_owner        = idOwner,
                notes           = Notes,
                pickup_location = PickupLocation,
                price           = Price.Value,
                start_rent      = StartRent,
                status          = Status.ToString(),
                discount        = Discount,
                updated_by      = username,
                updated_time    = DateTimeOffset.Now,
                id_car_package  = IdCarPackage,
                package_price   = (int)PackagePrice
            };

            return(dbItem);
        }
Exemple #2
0
        public ViewResult PrintQuotation(Guid id)
        {
            rent dbItem = RepoRent.FindByPk(id);
            List <rent_package>     listRentPackage = RepoRent.FindAllRentPackage().Where(n => n.id_rent == id).ToList();
            BookingPresentationStub model           = new BookingPresentationStub(dbItem, listRentPackage);

            return(View(model));
        }
Exemple #3
0
        public BookingPresentationStub(rent dbItem, List <rent_package> listRentPackage)
        {
            //kamus
            string     pn = dbItem.customer.phone_number.Replace('_', ' ');
            RentStatus rs;

            string[] arrPn;

            //algoritma
            if (pn != null)
            {
                arrPn = pn.Split(';');
                pn    = string.Join("<br>", arrPn);
            }

            Id          = dbItem.id;
            Code        = dbItem.code;
            PhoneNumber = pn;
            //IdCarpackage = dbItem.id_car_package;

            Name           = dbItem.customer.name;
            PickupLocation = dbItem.pickup_location;
            Logo           = dbItem.owner.logo;
            Contact        = dbItem.owner.contact;
            Terms          = dbItem.owner.terms;
            if (dbItem.id_driver.HasValue)
            {
                DriverName = dbItem.driver.name;
            }
            CarModelName = dbItem.car_model.name;
            if (dbItem.id_car.HasValue)
            {
                LicensePlate = dbItem.car.license_plate;
            }
            StartRent  = dbItem.start_rent;
            FinishRent = dbItem.finish_rent;
            Price      = dbItem.price;
            Notes      = dbItem.notes;

            if (dbItem.status != null)
            {
                rs         = (RentStatus)Enum.Parse(typeof(RentStatus), dbItem.status);
                StatusEnum = rs.ToString();
                Status     = new EnumHelper().GetEnumDescription(rs);
            }

            CancelNotes = dbItem.cancel_notes;
            CreatedBy   = dbItem.created_by;
            CreatedTime = dbItem.created_time;
            UpdateBy    = dbItem.updated_by;

            if (dbItem.updated_time.HasValue)
            {
                UpdatedTimeUtc = dbItem.updated_time.Value.UtcDateTime;
            }

            ListRentPackage = listRentPackage;
        }
Exemple #4
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            rent rent = await db.rents.FindAsync(id);

            db.rents.Remove(rent);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemple #5
0
        public async Task <ActionResult> Edit([Bind(Include = "rent_id,year,cost_rent")] rent rent)
        {
            if (ModelState.IsValid)
            {
                db.Entry(rent).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(rent));
        }
Exemple #6
0
        public async Task <ActionResult> Create([Bind(Include = "rent_id,year,cost_rent")] rent rent)
        {
            if (ModelState.IsValid)
            {
                db.rents.Add(rent);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(rent));
        }
Exemple #7
0
        public BookingFormStub(rent dbItem, List <car_package> listPackage)
        {
            EnumHelper  eh      = new EnumHelper();
            car_package package = new car_package();

            Id             = dbItem.id;
            Code           = dbItem.code;
            PickupLocation = dbItem.pickup_location;
            IdDriver       = dbItem.id_driver;
            IdCarModel     = dbItem.id_car_model;
            IdCar          = dbItem.id_car;

            StartRent    = dbItem.start_rent;
            FinishRent   = dbItem.finish_rent;
            PackagePrice = dbItem.package_price;
            Discount     = dbItem.discount;
            if (dbItem.id_car_package.HasValue)
            {
                IdCarPackage = dbItem.id_car_package.Value;
            }
            Price       = dbItem.price;
            Notes       = dbItem.notes;
            Status      = (RentStatus)Enum.Parse(typeof(RentStatus), dbItem.status);
            CancelNotes = dbItem.cancel_notes;

            //customer data
            if (dbItem.customer.phone_number != null)
            {
                string[] words = dbItem.customer.phone_number.Split(';');
                this.PhoneNumber = words[0];

                if (words.Count() > 1)
                {
                    this.PhoneNumber2 = words[1];
                }
            }
            IdCustomer = dbItem.id_customer;
            Name       = dbItem.customer.name;
            Address    = dbItem.customer.address;
            if (dbItem.customer.title != null)
            {
                CustomerTitle = (CustomerTitle)Enum.Parse(typeof(CustomerTitle), dbItem.customer.title);
            }

            ListRentPackageItem = new List <RentPackageFormStub>();
            foreach (rent_package single in dbItem.rent_package)
            {
                ListRentPackageItem.Add(new RentPackageFormStub(single));
            }
            ListRentPackageText = new JavaScriptSerializer().Serialize(ListRentPackageItem);
        }
Exemple #8
0
        // GET: rents/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            rent rent = await db.rents.FindAsync(id);

            if (rent == null)
            {
                return(HttpNotFound());
            }
            return(View(rent));
        }
Exemple #9
0
        public JsonResult GetBooking(Guid id)
        {
            List <string> result = new List <string>();

            if (id != null)
            {
                rent r = RepoRent.FindByPk(id);
                result.Add(r.customer.name);
                result.Add(r.start_rent.ToString(new DisplayFormatHelper().FullDateFormat) + " s/d " + r.finish_rent.ToString(new DisplayFormatHelper().FullDateFormat));
                result.Add(r.price.ToString());
                result.Add(r.code);
            }
            return(Json(result));
        }
Exemple #10
0
 public void UpdateDbObject(rent dbItem, CustomPrincipal user)
 {
     dbItem.cancel_notes    = CancelNotes;
     dbItem.finish_rent     = FinishRent;
     dbItem.id_car          = IdCar;
     dbItem.id_car_model    = IdCarModel.Value;
     dbItem.id_customer     = IdCustomer.Value;
     dbItem.id_driver       = IdDriver;
     dbItem.notes           = Notes;
     dbItem.pickup_location = PickupLocation;
     dbItem.price           = Price.Value;
     dbItem.start_rent      = StartRent;
     dbItem.status          = Status.ToString();
     dbItem.updated_by      = user.Identity.Name;
     dbItem.discount        = Discount;
     dbItem.updated_time    = DateTimeOffset.Now;
     dbItem.id_car_package  = IdCarPackage;
     dbItem.package_price   = (int)PackagePrice;
 }
Exemple #11
0
        public ActionResult Edit(Guid id)
        {
            rent dbItem  = RepoRent.FindByPk(id);
            Guid?idOwner = (User as CustomPrincipal).IdOwner;
            List <car_package> listCarPackage = RepoCarPackage.FindAll().Where(n => n.id_owner == idOwner).ToList();

            if (dbItem == null)
            {
                var wrapper = new HttpContextWrapper(System.Web.HttpContext.Current);
                return(this.InvokeHttp404(wrapper));
            }

            BookingFormStub model = new BookingFormStub(dbItem, listCarPackage);

            FillModelOptions(model);

            ViewBag.name = "Booking " + model.Name;

            return(View("Form", model));
        }
Exemple #12
0
        public Rent(rent dbItem)
        {
            this.RentCode            = dbItem.code;
            this.CustomerName        = dbItem.customer.name;
            this.CustomerPhoneNumber = dbItem.customer.phone_number;
            this.PickupLocation      = dbItem.pickup_location;

            if (dbItem.driver != null)
            {
                this.DriverName = dbItem.driver.name;
            }

            this.CarBrandName = dbItem.car_model.car_brand.name;
            this.CarModelName = dbItem.car_model.name;

            if (dbItem.car != null)
            {
                this.CarLicensePlate = dbItem.car.license_plate;
            }

            this.StartRent  = new DateTime(dbItem.start_rent.Year, dbItem.start_rent.Month, dbItem.start_rent.Day, dbItem.start_rent.Hour, dbItem.start_rent.Minute, dbItem.start_rent.Second);
            this.FinishRent = new DateTime(dbItem.finish_rent.Year, dbItem.finish_rent.Month, dbItem.finish_rent.Day, dbItem.finish_rent.Hour, dbItem.finish_rent.Minute, dbItem.finish_rent.Second);
        }
Exemple #13
0
        public Guid Save(rent dbItem)
        {
            if (dbItem.id == Guid.Empty) //create
            {
                dbItem.id = Guid.NewGuid();

                context.rents.Add(dbItem);
            }
            else //edit
            {
                context.rents.Attach(dbItem);

                var entry = context.Entry(dbItem);
                entry.State = EntityState.Modified;

                //field yang tidak ditentukan oleh user
                //entry.Property(e => e.is_delete).IsModified = false;
            }

            context.SaveChanges();

            return(dbItem.id);
        }
Exemple #14
0
        public ActionResult Create(BookingFormStub model, bool print = false)
        {
            if (model.Status != RentStatus.CANCEL)
            {
                ModelState.Remove("CancelNotes");
            }
            if (model.IdCarPackage == Guid.Empty)
            {
                ModelState.Remove("IdCarPackage");
            }

            if (model.ListRentPackageText != null)
            {
                model.ListRentPackageItem = new JavaScriptSerializer().Deserialize <List <RentPackageFormStub> >(model.ListRentPackageText);
            }
            ModelState.Remove("PriceDay");
            //ModelState.Remove("Price");

            if (ModelState.IsValid)
            {
                CustomPrincipal user = User as CustomPrincipal;

                //melengkapi data model
                owner owner = RepoOwner.FindByPk(user.IdOwner.Value);
                model.Code = RepoRent.GenerateRentCode(owner);

                customer cust;
                if (model.IdCustomer.HasValue == false)
                {
                    cust = model.CreateNewCustomer(user.IdOwner.Value);
                    RepoCustomer.Save(cust);
                    model.IdCustomer = cust.id;
                }
                else
                {
                    cust = RepoCustomer.FindByPk(model.IdCustomer.Value);
                    model.UpdateCustomer(cust);

                    RepoCustomer.Save(cust);
                }

                //save to db
                rent dbItem = model.GetDbObjectOnCreate(user.Identity.Name, user.IdOwner.Value);
                //RepoRent.Save(dbItem);

                Guid idRentPackage = RepoRent.Save(dbItem);

                if (model.ListRentPackageItem != null && model.ListRentPackageItem.Count() > 0)
                {
                    foreach (RentPackageFormStub single in model.ListRentPackageItem)
                    {
                        RepoRent.SaveListPackage(single.GetDbObject(idRentPackage, single.IdCarPackage));
                    }
                }

                //message
                string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString();
                this.SetMessage("Booking " + model.Name, template);

                //print flag
                if (print)
                {
                    TempData["idPrint"] = dbItem.id;
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                FillModelOptions(model);

                return(View("Form", model));
            }
        }
Exemple #15
0
 public void Delete(rent dbItem)
 {
     context.rents.Remove(dbItem);
     context.SaveChanges();
 }
Exemple #16
0
 public void SetNewRent(rent dbItem, string partner)
 {
     IdRent  = dbItem.id;
     Status  = ApiRentStatus.NEW;
     Partner = partner;
 }
Exemple #17
0
        public RentResponse Create([FromBody] RentParam param)
        {
            //kamus
            RentResponse        result   = new RentResponse();
            DisplayFormatHelper dfh      = new DisplayFormatHelper();
            List <Guid>         idCar    = new List <Guid>();
            List <car_model>    carModel = new List <car_model>();

            rent        dataRent = new rent();
            List <rent> rents    = new List <rent>();
            Dictionary <string, Guid> cityMap;
            Guid idOwner = new Guid();

            string          code;
            string          city;
            Guid            customerId;
            List <customer> customerList;

            bool isDataValid = true;

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };

            DateTime       dtStart, dtFinish;
            DateTimeOffset dtoStart, dtoFinish;
            DateTime       dtNull = DateTime.Parse("01/01/0001 00:00:00");

            List <car>  ownerCars = new List <car>();
            List <Guid> rentedCars;

            BookingFormStub bfs;
            rent            dbItem;

            ApiRentFormStub afs;
            api_rent        apiRent;
            log_api_rent    logApiRent;

            //hardcode data
            cityMap = new Dictionary <string, Guid>();
            cityMap.Add("bali", new Guid("9e9af49f-742a-40a2-9338-228e56060442"));
            cityMap.Add("surabaya", new Guid("7a683eb8-656d-4b4c-be71-157dd2328a64"));

            //algoritma
            #region check data
            //mengecek validitas parameter
            if (param.StartRent == null)
            {
                isDataValid = false;

                result.Success = false;
                result.Message = "Parameter StartRent wajib diisi";
            }

            if (isDataValid)
            {
                if (param.FinishRent == null)
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter FinishRent wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.City == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter City wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CarBrandName == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CarBrandName wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CarModelName == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CarModelName wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CustomerName == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CustomerName wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.CustomerPhoneNumber == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter CustomerPhoneNumber wajib diisi";
                }
            }

            if (isDataValid)
            {
                if (param.PickupLocation == "")
                {
                    isDataValid = false;

                    result.Success = false;
                    result.Message = "Parameter PickupLocation wajib diisi";
                }
            }


            if (isDataValid)
            {
                city = param.City.ToLower();
                if (cityMap.ContainsKey(city))
                {
                    idOwner = cityMap[city];
                }
                else
                {
                    isDataValid    = false;
                    result.Message = "Kota yang anda pilih saat ini belum tersedia";
                }
            }

            if (isDataValid)
            {
                //mengambil semua mobil milik owner
                filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                });
                if (param.CarBrandName != null)
                {
                    filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                        Field = "car_model.car_brand.name", Operator = "eq", Value = param.CarBrandName
                    });
                }
                if (param.CarModelName != null)
                {
                    filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                        Field = "car_model.name", Operator = "eq", Value = param.CarModelName
                    });
                }
                ownerCars = RepoCar.FindAll(null, null, null, filters);

                //mengambil booking pada tanggal sesuai request
                dtStart  = new DateTime(param.StartRent.Value.Year, param.StartRent.Value.Month, param.StartRent.Value.Day, 0, 0, 0);
                dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
                dtoStart = dtStart;

                dtFinish  = new DateTime(param.FinishRent.Value.Year, param.FinishRent.Value.Month, param.FinishRent.Value.Day, 23, 59, 59);
                dtFinish  = DateTime.SpecifyKind(dtFinish, DateTimeKind.Local);
                dtoFinish = dtFinish;
                rents     = RepoRent.FindAll(idOwner, dtStart, dtFinish);

                rents.RemoveAll(m => m.finish_rent == dtoStart);
                rents.RemoveAll(m => m.start_rent == dtoFinish);

                rentedCars = rents.Select(m => m.id_car_model).ToList();

                //menghapus mobil yang sudah di-booking
                car carByModel;
                foreach (Guid idCarModel in rentedCars)
                {
                    carByModel = ownerCars.Where(m => m.id_car_model == idCarModel).FirstOrDefault();
                    if (carByModel != null)
                    {
                        ownerCars.Remove(carByModel);
                    }
                }

                if (ownerCars.Count() == 0)
                {
                    isDataValid    = false;
                    result.Message = "Mobil tidak tersedia";
                }
            }

            #endregion

            if (isDataValid)//insert booking
            {
                //mengecek ketersediaan mobil
                owner owner = RepoOwner.FindByPk(idOwner);
                code = RepoRent.GenerateRentCode(owner);

                //membuat booking baru
                customerList = new List <customer>();
                Business.Infrastructure.FilterInfo filterCust = new Business.Infrastructure.FilterInfo {
                    Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
                };
                filterCust.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "phone_number", Operator = "eq", Value = param.CustomerPhoneNumber
                });
                filterCust.Filters.Add(new Business.Infrastructure.FilterInfo {
                    Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
                });

                customerList = RepoCustomer.FindAll(null, null, null, filterCust);

                if (customerList.Count() > 0)
                {
                    customerId = customerList.FirstOrDefault().id;
                }
                else
                {
                    customer cust = new customer
                    {
                        name         = param.CustomerName,
                        id_owner     = idOwner,
                        phone_number = param.CustomerPhoneNumber
                    };
                    RepoCustomer.Save(cust);

                    customerId = cust.id;
                }


                //if (tempCustomer.Where(n => n.phone_number == param.CustomerPhoneNumber && n.id_owner != idOwner).Count() > 0)
                //{
                //    CustomerID = new Guid();
                //    customer cust = new customer
                //    {
                //        id = CustomerID,
                //        name = param.CustomerName,
                //        id_owner = idOwner,
                //        phone_number = param.CustomerPhoneNumber
                //    };
                //    RepoCustomer.Save(cust);
                //}

                //membuat BookingFormStub
                bfs = new BookingFormStub();

                dtStart  = new DateTime(param.StartRent.Value.Year, param.StartRent.Value.Month, param.StartRent.Value.Day, param.StartRent.Value.Hour, param.StartRent.Value.Minute, param.StartRent.Value.Second);
                dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
                dtoStart = dtStart;

                dtFinish  = new DateTime(param.FinishRent.Value.Year, param.FinishRent.Value.Month, param.FinishRent.Value.Day, param.FinishRent.Value.Hour, param.FinishRent.Value.Minute, param.FinishRent.Value.Second);
                dtFinish  = DateTime.SpecifyKind(dtFinish, DateTimeKind.Local);
                dtoFinish = dtFinish;

                bfs.Code           = code;
                bfs.PhoneNumber    = param.CustomerPhoneNumber;
                bfs.IdCustomer     = customerId;
                bfs.PickupLocation = param.PickupLocation;
                bfs.IdCarModel     = ownerCars.FirstOrDefault().id_car_model;
                bfs.StartRent      = dtoStart;
                bfs.FinishRent     = dtoFinish;
                bfs.Price          = 0;
                bfs.Status         = RentStatus.NEW;
                bfs.IdCarPackage   = new Guid("0abd31d3-2857-4311-a468-48538bbd790c");
                bfs.PackagePrice   = 0;

                //save
                dbItem = bfs.GetDbObjectOnCreate("aerotrans", idOwner);
                RepoRent.Save(dbItem);

                //save to table api_rent
                afs = new ApiRentFormStub();
                afs.SetNewRent(dbItem, "ATS");
                apiRent = afs.GetDbObjectOnCreate("aerotrans");

                RepoApiRent.Save(apiRent);

                result.Success  = true;
                result.RentCode = code;
            }

            return(result);
        }
Exemple #18
0
        public ActionResult Edit(BookingFormStub model, bool print = false)
        {
            if (model.ListRentPackageText != null && model.ListRentPackageText != "")
            {
                model.ListRentPackageItem = new JavaScriptSerializer().Deserialize <List <RentPackageFormStub> >(model.ListRentPackageText);
            }
            List <rent_package> pakets;
            RentPackageFormStub rentPackageFS;

            rent dbItem = RepoRent.FindByPk(model.Id);

            if (model.Status != RentStatus.CANCEL)
            {
                ModelState.Remove("CancelNotes");
            }

            if (ModelState.IsValid)
            {
                CustomPrincipal user = User as CustomPrincipal;

                //process customer
                customer cust;
                if (model.IdCustomer.HasValue == false)
                {
                    cust = model.CreateNewCustomer(user.IdOwner.Value);
                    RepoCustomer.Save(cust);
                    model.IdCustomer = cust.id;
                }
                else
                {
                    cust = RepoCustomer.FindByPk(model.IdCustomer.Value);
                    model.UpdateCustomer(cust);

                    RepoCustomer.Save(cust);
                }

                //save to db
                model.UpdateDbObject(dbItem, user);
                RepoRent.Save(dbItem);

                //save rent_package
                pakets = dbItem.rent_package.ToList();
                foreach (rent_package paket in pakets.ToList())
                {
                    RepoRent.DeleteRentPackage(paket);
                }

                if (model.ListRentPackageItem != null && model.ListRentPackageItem.Count() > 0)
                {
                    foreach (RentPackageFormStub single in model.ListRentPackageItem)
                    {
                        RepoRent.SaveListPackage(single.GetDbObject(model.Id, single.IdCarPackage));
                    }
                }



                //rent_package idCarPackage;
                //foreach (RentPackageFormStub Single in model.ListRentPackageItem)
                //{
                //    idCarPackage = pakets.Where(n => n.id_rent == Single.IdRent).FirstOrDefault();
                //    foreach (rent_package paket in pakets)
                //    {
                //        if (idCarPackage.id_car_package != paket.id_car_package)
                //        {
                //            pakets.Remove(paket);
                //            //rentPackageFS.SetDbObject(paket);
                //            //RepoRent.SaveListPackage(paket);
                //        }
                //    }
                //}

                //foreach (rent_package paket in pakets)
                //{
                //    //idCarPackage = pakets.Where(n => n.id_car_package == paket.id_car_package).FirstOrDefault();
                //    rentPackageFS = model.ListRentPackageItem.Where(n => n.IdRent == paket.id_rent).FirstOrDefault();
                //    if (rentPackageFS != null)
                //    {
                //        rentPackageFS.SetDbObject(paket);
                //        RepoRent.SaveListPackage(paket);
                //    }
                //}

                //message
                string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "EditSuccess").ToString();
                this.SetMessage("Booking " + model.Name, template);

                //print flag
                if (print)
                {
                    TempData["idPrint"] = dbItem.id;
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                model.Code = dbItem.code;
                FillModelOptions(model);

                ViewBag.name = "Booking " + dbItem.customer.name;

                return(View("Form", model));
            }
        }
Exemple #19
0
        private void Rent()
        {
            MessageBoxResult mbrTmp = MessageBox.Show("Czy na pewno wypożyczyć te urządzenia?", "Pytanie", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);

            if (mbrTmp == MessageBoxResult.Yes)
            {
                rent RentToAdd = new rent();
                RentToAdd.date_of_rent   = RentDateStart;
                RentToAdd.date_of_return = RentDateEnd;
                RentToAdd.total_price    = TotalCostWithDiscount;

                try
                {
                    RentToAdd.subscription_id = Convert.ToInt16(SubscriptionId);
                }
                catch (Exception e)
                {
                    File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString());
                    System.Windows.MessageBox.Show("Nie powiodło się pobranie abonenta z bazy. Sprawdź dane.");
                    return;
                }

                using (SubscriptionContext context = new SubscriptionContext())
                {
                    try
                    {
                        context.rents.Add(RentToAdd);
                        context.SaveChanges();

                        foreach (device dev in CollectionOfDevices)
                        {
                            if (dev.IsChecked)
                            {
                                var    result         = (from d in context.devices where dev.deviceId == d.deviceId select d).First();
                                device deviceToUpdate = (device)result;
                                context.devices.Attach(deviceToUpdate);
                                deviceToUpdate.is_rented = true;

                                //dodawanie do bazy wpisu o wypozyczeniu do tabeli pośredniej miedzy wyporzyczeniami a urzadzeniami
                                devices_rents devRentToAdd = new devices_rents();
                                devRentToAdd.device_id = deviceToUpdate.deviceId;
                                devRentToAdd.rent_id   = RentToAdd.rentId;

                                context.devices_rents.Add(devRentToAdd);
                            }
                        }



                        context.SaveChanges();
                        System.Windows.MessageBox.Show("Dodano wypożyczenie.");

                        //aktualizacja danych na liście urządzeń
                        //(wypozyczono coś, wiec trzeba to usunąc z listy dostepnych do wypozyczenia)

                        var result2 = (from d in context.devices select d).ToList();
                        CollectionOfDevices = new ObservableCollection <device>();

                        //odrzucenie urządzeń ktore sa aktualnie wypozyczone
                        foreach (device dev in result2)
                        {
                            if (!dev.is_rented)
                            {
                                CollectionOfDevices.Add(dev);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString());
                        System.Windows.MessageBox.Show("Nie powiodło się dodanie wypożyczenia do bazy. Sprawdź dane.");
                        return;
                    }
                }
            }
        }
Exemple #20
0
        public HttpResponseMessage Submit([FromBody] DriverPositionParam param)
        {
            //kamus
            BookingPresentationStub result = new BookingPresentationStub();
            rent          rent             = new rent();
            bool          isDatavalid      = true;
            List <rent>   listRent         = new List <rent>();
            rent_position rentPos          = new rent_position();
            string        username         = null;

            IEnumerable <string> headerValues = Enumerable.Empty <string>();
            HttpStatusCode       httpStatus   = HttpStatusCode.InternalServerError;
            string responseMessage            = null;

            rent = RepoRent.FindByPk(param.Id);

            //algoritma
            //Mengecek Parameter
            //jika ID kosong, 403 Forbidden
            if (param.Id == Guid.Empty)
            {
                isDatavalid     = false;
                responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "OrderNullAlert").ToString();
                httpStatus      = HttpStatusCode.Forbidden;
            }

            //cek username
            if (isDatavalid)
            {
                if (Request.Headers.TryGetValues("Username", out headerValues))
                {
                    username = headerValues.FirstOrDefault();
                }
                else
                {
                    isDatavalid     = false;
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "UsernameNullAlert").ToString();
                    httpStatus      = HttpStatusCode.Forbidden;
                }
            }

            //jika Username tidak sama dg username driver
            if (isDatavalid)
            {
                rent = RepoRent.FindByPk(param.Id);
                if ((rent == null) || (rent.driver == null) || (username != rent.driver.username))
                {
                    isDatavalid     = false;
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "NotAccess").ToString();
                    httpStatus      = HttpStatusCode.Forbidden;
                }
            }

            // Status Check
            //mengambil rent milik id Driver
            if (isDatavalid)
            {
                // Jika rent status GO => menyimpan kedatabase rent_position
                if (rent.status == RentStatus.GO.ToString())
                {
                    rentPos.id_rent      = rent.id;
                    rentPos.longitude    = param.Long;
                    rentPos.latitude     = param.Lat;
                    rentPos.created_by   = rent.driver.username;
                    rentPos.created_time = DateTime.Now;
                    RepoPos.Save(rentPos);
                    httpStatus = HttpStatusCode.OK;
                }
                // Jika rent status NEW => 500 Internal server error
                else if (rent.status == RentStatus.NEW.ToString())
                {
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "NewAlert").ToString();
                    httpStatus      = HttpStatusCode.InternalServerError;
                }
                // Jika rent status FINISH => 500 Internal server error
                else if (rent.status == RentStatus.FINISH.ToString())
                {
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "FinishAlert").ToString();
                    httpStatus      = HttpStatusCode.InternalServerError;
                }
                // Jika rent status CANCEL => 500 Internal Server error
                else
                {
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "CancelAlert").ToString();
                    httpStatus      = HttpStatusCode.InternalServerError;
                }
            }

            if (responseMessage != null)
            {
                HttpContext.Current.Response.AppendHeader("ResponseMessage", responseMessage);
            }

            return(Request.CreateResponse(httpStatus));
        }
Exemple #21
0
        public string Add()
        {
            //kamus
            string          code;
            Guid            idOwner = new Guid("156c2cde-2c19-46c3-bcba-a27f9d1e4998");
            owner           owner   = RepoOwner.FindByPk(idOwner);
            BookingFormStub bfs     = new BookingFormStub();

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo
            {
                Filters = new List <Business.Infrastructure.FilterInfo>
                {
                    new Business.Infrastructure.FilterInfo {
                        Field = "name", Operator = "eq", Value = "Avanza"
                    }
                },
                Logic = "and"
            };
            car_model      cm;
            DateTime       dtStart, dtFinish;
            DateTimeOffset dtoStart, dtoFinish;

            //algoritma
            code = RepoRent.GenerateRentCode(owner);

            bfs.IdCustomer     = new Guid("54612b5e-611f-4b71-9dbd-ed35b6f2976b");
            bfs.Code           = code;
            bfs.PickupLocation = "Jl. Sudirman no. 16";

            cm = RepoCarModel.Find(null, filters);
            if (cm != null)
            {
                bfs.IdCarModel = cm.id;
            }

            dtStart  = new DateTime(2016, 6, 4, 8, 0, 0);
            dtStart  = DateTime.SpecifyKind(dtStart, DateTimeKind.Local);
            dtoStart = dtStart;

            dtFinish  = new DateTime(2016, 6, 4, 8, 0, 0);
            dtFinish  = DateTime.SpecifyKind(dtFinish, DateTimeKind.Local);
            dtoFinish = dtFinish;

            bfs.StartRent  = dtoStart;
            bfs.FinishRent = dtoFinish;

            bfs.Price  = 300000;
            bfs.Status = RentStatus.NEW;

            //save rent
            rent dbItem = bfs.GetDbObjectOnCreate("dummy", idOwner);

            RepoRent.Save(dbItem);

            //save notification
            NotificationFormStub nfs = new NotificationFormStub();

            nfs.Message = "Booking baru dari Citylink Cars";
            nfs.IdOwner = idOwner;

            d_notification notif = nfs.GetDBobject(idOwner);

            RepoDummyNotification.Save(notif);

            return(new JavaScriptSerializer().Serialize(bfs));
        }
Exemple #22
0
 public RentPresentationStub(rent dbItem)
 {
     Base        = new BookingPresentationStub(dbItem);
     CreatedTime = dbItem.created_time;
     OwnerName   = dbItem.owner.name;
 }
Exemple #23
0
        public HttpResponseMessage Submit([FromBody] DriverRentParam param)
        {
            //kamus
            BookingPresentationStub result = new BookingPresentationStub();
            rent rent        = new rent();
            bool isDatavalid = true;
            IEnumerable <string> headerValues;
            HttpStatusCode       httpStatus = HttpStatusCode.InternalServerError;
            string responseMessage          = null;
            string username = null;

            // Mengecek parameter
            //jika ID kosong, 403 Forbidden
            if (param.Id == Guid.Empty)
            {
                isDatavalid     = false;
                responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "OrderNullAlert").ToString();
                httpStatus      = HttpStatusCode.Forbidden;
            }

            //cek username
            if (isDatavalid)
            {
                if (Request.Headers.TryGetValues("Username", out headerValues))
                {
                    username = headerValues.FirstOrDefault();
                }
                else
                {
                    isDatavalid     = false;
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "UsernameNullAlert").ToString();
                    httpStatus      = HttpStatusCode.Forbidden;
                }
            }

            //jika Username tidak sama dg username driver
            if (isDatavalid)
            {
                rent = RepoRent.FindByPk(param.Id);
                if ((rent == null) || (rent.driver == null) || (username != rent.driver.username))
                {
                    isDatavalid     = false;
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "NotAccess").ToString();
                    httpStatus      = HttpStatusCode.Forbidden;
                }
            }

            // Pengecekan Status
            //mengambil rent milik idDriver
            if (isDatavalid)
            {
                // untuk merubah status dari NEW ke GO
                if (rent.status == RentStatus.GO.ToString())
                {
                    rent.status       = RentStatus.FINISH.ToString();
                    rent.updated_by   = rent.driver.username;
                    rent.updated_time = DateTime.Now;
                    RepoRent.Save(rent);

                    httpStatus = HttpStatusCode.OK;
                }
                // untuk mengecek status, jika NEW => 500 internal server error
                else if (rent.status == RentStatus.NEW.ToString())
                {
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "NewAlert").ToString();
                    httpStatus      = HttpStatusCode.InternalServerError;
                }
                // untuk mengecek status, jika FINISH => 500 internal server error
                else if (rent.status == RentStatus.FINISH.ToString())
                {
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "FinishAlert").ToString();
                    httpStatus      = HttpStatusCode.InternalServerError;
                }
                // untuk mengecek status, jika CANCEL => 500 internal server error
                else
                {
                    responseMessage = HttpContext.GetGlobalResourceObject("WebServiceMessage", "CancelAlert").ToString();
                    httpStatus      = HttpStatusCode.InternalServerError;
                }
            }

            if (responseMessage != null)
            {
                HttpContext.Current.Response.AppendHeader("ResponseMessage", responseMessage);
            }
            return(Request.CreateResponse(httpStatus));
        }