示例#1
0
        public ActionResult Create()
        {
            BookingFormStub model = new BookingFormStub();

            FillModelOptions(model);

            return(View("Form", model));
        }
示例#2
0
        private void FillModelOptions(BookingFormStub model)
        {
            Guid idOwner = (User as CustomPrincipal).IdOwner.Value;
            List <car_package> result = new List <car_package>();

            Business.Infrastructure.FilterInfo filters = new Business.Infrastructure.FilterInfo {
                Filters = new List <Business.Infrastructure.FilterInfo>(), Logic = "and"
            };
            filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                Field = "id_owner", Operator = "eq", Value = idOwner.ToString()
            });
            filters.Filters.Add(new Business.Infrastructure.FilterInfo {
                Field = "is_active", Operator = "eq", Value = true.ToString()
            });

            result = RepoCarPackage.FindAll(null, null, null, filters);

            model.SetCarPackageOptions(result);
        }
示例#3
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));
        }
示例#4
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));
            }
        }
示例#5
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));
            }
        }
示例#6
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);
        }
示例#7
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));
        }