public IActionResult Update(ParkingLotViewModel model)
        {
            if (ModelState.IsValid)
            {
                ResponseDetails response = _apiHelper.SendApiRequest(model, "parkinglot/update", HttpMethod.Post);

                if (response.Success)
                {
                    return(RedirectToAction("Details", new { id = _dataProtector.Protect(model.Id) }));
                }
                else
                {
                    ErrorViewModel errorModel = new ErrorViewModel
                    {
                        Message = response.Data.ToString()
                    };

                    return(View("Error", errorModel));
                }
            }
            else
            {
                ModelState.AddModelError("Error", "Validation Error");
                return(View(model));
            }
        }
示例#2
0
        public IActionResult Create(ParkingLotViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                //if (_dbContext.ParkingLot.Count(x => x.MemberName == model.MemberName) > 0)
                //{
                //    response.SetFailed("名称已存在");
                //    return Ok(response);
                //}

                var entity = _mapper.Map <ParkingLotViewModel, ParkingLot>(model);
                entity.ParkingLotUuid = Guid.NewGuid();
                entity.IsDeleted      = 0;

                entity.AddTime   = DateTime.Now.ToString("yyyy-MM-dd");
                entity.AddPeople = AuthContextService.CurrentUser.DisplayName;

                _dbContext.ParkingLot.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:停车场信息一条数据", _dbContext);
                }
                response.SetSuccess();
                return(Ok(response));
            }
        }
示例#3
0
        public IActionResult ParkingLot(string id)
        {
            int newId = _dataProtector.Unprotect(id);

            ResponseDetails response = _apiHelper.SendApiRequest("", "parkinglot/get/" + newId, HttpMethod.Get);

            if (response.Success)
            {
                ParkingLotViewModel model = JsonConvert.DeserializeObject <ParkingLotViewModel>
                                                (response.Data.ToString());

                _dataProtector.ProtectParkingLotRouteValues(model);

                model.SlotViewModels = model.SlotViewModels.Select(x =>
                {
                    // populate can book property logic
                    x.CanBook = CanBookSlot(x);

                    _dataProtector.ProtectSlotRouteValues(x);

                    return(x);
                }).ToList();

                return(View(model));
            }
            else
            {
                ErrorViewModel model = new ErrorViewModel
                {
                    Message = response.Data.ToString()
                };

                return(View("Error", model));
            }
        }
        private static ParkingLotViewModel CalculateHourlyRate(ParkingLotViewModel model)
        {
            int TwoWheelerTotal       = 0;
            int FourWheelerTotal      = 0;
            int totalTwoWheelerSlots  = 0;
            int totalFourWheelerSlots = 0;

            model.SlotViewModels.ForEach(s =>
            {
                if (s.SlotTypeViewModel.Title == "2 Wheel")
                {
                    TwoWheelerTotal += s.HourlyRate;
                    totalTwoWheelerSlots++;
                }
                else
                {
                    FourWheelerTotal += s.HourlyRate;
                    totalFourWheelerSlots++;
                }
            });

            model.TwoWheelerHourlyRate  = TwoWheelerTotal / totalTwoWheelerSlots;
            model.FourWheelerHourlyRate = FourWheelerTotal / totalFourWheelerSlots;

            return(model);
        }
示例#5
0
        public IActionResult Edit(ParkingLotViewModel model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = _dbContext.ParkingLot.FirstOrDefault(x => x.ParkingLotUuid == model.ParkingLotUuid);
                if (entity == null)
                {
                    response.SetFailed("不存在");
                    return(Ok(response));
                }
                //if (_dbContext.ParkingLot.Count(x => x.TeamName == model.TeamName && x.ParkingLotUuid != model.ParkingLotUuid) > 0)
                //{
                //    response.SetFailed("名称已存在");
                //    return Ok(response);
                //}
                entity.ParkingLotName    = model.ParkingLotName;
                entity.ParkingLotAddress = model.ParkingLotAddress;
                entity.Zchewei           = model.Zchewei;
                entity.Ychewei           = model.Ychewei;
                entity.Schewei           = model.Schewei;
                //entity.Schewei = model.Schewei;
                entity.Lon = model.Lon;
                entity.Lat = model.Lat;
                // entity.ParkingLotsru = model.ParkingLotsru;
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("编辑", "成功:编辑:停车场信息一条数据", _dbContext);
                }
                response = ResponseModelFactory.CreateInstance;
                return(Ok(response));
            }
        }
        public IActionResult Details(string id)
        {
            int newId = _dataProtector.Unprotect(id);

            ResponseDetails response = _apiHelper.SendApiRequest("", "parkinglot/get/" + newId, HttpMethod.Get);

            if (response.Success)
            {
                ParkingLotViewModel model = JsonConvert.DeserializeObject <ParkingLotViewModel> (response.Data.ToString());

                model = CalculateHourlyRate(model);
                _dataProtector.ProtectParkingLotRouteValues(model);

                return(View(model));
            }
            else
            {
                ErrorViewModel model = new ErrorViewModel
                {
                    Message = response.Data.ToString()
                };

                return(View("Error", model));
            }
        }
示例#7
0
        public Parking()
        {
            InitializeComponent();
            ParkingLotViewModel x = new ParkingLotViewModel();

            //Added binding context, it should be changed by a resolver. (Autofac)
            this.BindingContext = x;
        }
        public IActionResult Add(AddParkingLotModel model)
        {
            if (ModelState.IsValid)
            {
                ParkingLotViewModel lot = new ParkingLotViewModel()
                {
                    Name             = model.Name,
                    IsActive         = true,
                    IsAproved        = false,
                    OwnerId          = _tokenDecoder.UserId,
                    AddressViewModel = model.AddressViewModel
                };

                for (int i = 0; i < model.NoOf2WheelSlot; i++)
                {
                    lot.SlotViewModels.Add(new SlotViewModel()
                    {
                        IsBooked   = false,
                        SlotTypeId = 1,
                        HourlyRate = model.TwoWheelerHourlyRate
                    });
                }

                for (int i = 0; i < model.NoOf4WheelSlot; i++)
                {
                    lot.SlotViewModels.Add(new SlotViewModel()
                    {
                        IsBooked   = false,
                        SlotTypeId = 2,
                        HourlyRate = model.FourWheelerHourlyRate
                    });
                }

                ResponseDetails response = _apiHelper.SendApiRequest(lot, "parkinglot/add", HttpMethod.Post);

                if (response.Success)
                {
                    return(RedirectToAction("Dashboard"));
                }
                else
                {
                    ErrorViewModel errorModel = new ErrorViewModel
                    {
                        Message = response.Data.ToString()
                    };

                    return(View("Error", errorModel));
                }
            }
            else
            {
                ModelState.AddModelError("Error", "Validation Error");
                return(View(model));
            }
        }
        public object Get(int id)
        {
            ParkingLotViewModel model = _parkingLotService.Get(id);

            if (model == null)
            {
                return(new ResponseDetails(false, $"Parking lot with Id : { id } not found."));
            }

            return(new ResponseDetails(true, model));
        }
示例#10
0
        public ParkingLotViewModel MapParkingLot(ParkingLot model)
        {
            ParkingLotViewModel modelMapping = _mapper.Map <ParkingLotViewModel> (model);

            modelMapping.AddressViewModel          = _mapper.Map <AddressViewModel> (model.Address);
            modelMapping.OwnerViewModel            = MapUser(model.Owner);
            modelMapping.ParkingLotImageViewModels = _mapper.Map <List <ParkingLotImageViewModel> > (model.ParkingLotImages);
            modelMapping.SlotViewModels            = MapSlots(model.Slots);

            return(modelMapping);
        }
        public object Update(ParkingLotViewModel model)
        {
            model = _parkingLotService.Update(model);

            if (model == null)
            {
                return(new ResponseDetails(false, $"Parking lot with Id : { model.Id } not found."));
            }

            return(new ResponseDetails(true, model));
        }
        public IActionResult Details(string id)
        {
            int newId = _dataProtector.Unprotect(id);

            ResponseDetails response = _apiHelper.SendApiRequest("", "parkinglot/get/" + newId, HttpMethod.Get);

            if (response.Success)
            {
                ParkingLotViewModel parkingLotViewModel = JsonConvert.DeserializeObject <ParkingLotViewModel>
                                                              (response.Data.ToString());

                _dataProtector.ProtectParkingLotRouteValues(parkingLotViewModel);

                ParkingLotRequestdetailsModel model = new ParkingLotRequestdetailsModel()
                {
                    ParkingLot = parkingLotViewModel
                };

                if (model.ParkingLot.ParkingLotImageViewModels.Any())
                {
                    response = _apiHelper.SendApiRequest("", "parkinglot/all-images/" + newId, HttpMethod.Get);

                    if (response.Success)
                    {
                        model.Images = JsonConvert.DeserializeObject <List <string> > (response.Data.ToString());

                        return(View(model));
                    }
                    else
                    {
                        ErrorViewModel errorModel = new ErrorViewModel
                        {
                            Message = response.Data.ToString()
                        };

                        return(View("Error", errorModel));
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            else
            {
                ErrorViewModel model = new ErrorViewModel
                {
                    Message = response.Data.ToString()
                };

                return(View("Error", model));
            }
        }
        public ActionResult EditParkingLot(int?id)
        {
            ParkingLotViewModel model = new ParkingLotViewModel();

            if (id.HasValue && id != 0)
            {
                ParkingLot parkingLotEntity = parkingLotService.Get(id.Value);
                model.Address     = parkingLotEntity.Address;
                model.CompanyName = parkingLotEntity.CompanyName;
                model.ZipCode     = parkingLotEntity.ZipCode;
            }
            return(View("EditParkingLot", model));
        }
示例#14
0
        private List <ParkingLotViewModel> MapParkingLots(List <ParkingLot> model)
        {
            List <ParkingLotViewModel> modelMapping = new List <ParkingLotViewModel> ();

            for (int i = 0; i < model.Count; i++)
            {
                ParkingLotViewModel viewModel = _mapper.Map <ParkingLotViewModel> (model[i]);
                viewModel.AddressViewModel = _mapper.Map <AddressViewModel> (model[i].Address);

                modelMapping.Add(viewModel);
            }

            return(modelMapping);
        }
示例#15
0
        public ParkingLotViewModel Update(ParkingLotViewModel model)
        {
            if (_unitOfWork.ParkingLotRepository.ParkingLotExists(model.Id))
            {
                ParkingLot modelMapping = _mapper.Map <ParkingLot> (model);

                _unitOfWork.ParkingLotRepository.Update(modelMapping);
                _unitOfWork.SaveChanges();

                return(model);
            }

            return(null);
        }
        public ActionResult AddParkingLot(ParkingLotViewModel model)
        {
            ParkingLot parkingLotEntity = new ParkingLot
            {
                CompanyName                  = model.CompanyName,
                Address                      = model.Address,
                ZipCode                      = model.ZipCode,
                AddedDate                    = DateTime.UtcNow,
                ModifiedDate                 = DateTime.UtcNow,
                InitialNumberOfFloors        = model.InitialNumberOfFloors,
                InitialNumberOfSpotsPerFloor = model.InitialNumberOfSpotsPerFloor
            };

            List <ParkingFloor> parkingFloors = new List <ParkingFloor>();

            for (int i = 0; i < model.InitialNumberOfFloors; i++)
            {
                ParkingFloor parkingFloor = new ParkingFloor
                {
                    AddedDate    = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow,
                };

                parkingFloor.ParkingSpots = new List <ParkingSpot>();

                for (int j = 0; j < model.InitialNumberOfSpotsPerFloor; j++)
                {
                    ParkingSpot parkingSpot = new ParkingSpot
                    {
                        AddedDate    = DateTime.UtcNow,
                        ModifiedDate = DateTime.UtcNow,
                    };

                    parkingSpot.ParkingFloor = parkingFloor;
                    parkingFloor.ParkingSpots.Add(parkingSpot);
                }

                parkingFloor.ParkingLot = parkingLotEntity;
                parkingFloors.Add(parkingFloor);
            }

            parkingLotEntity.ParkingFloors = parkingFloors;
            parkingLotService.Insert(parkingLotEntity);
            if (parkingLotEntity.Id > 0)
            {
                return(RedirectToAction("index"));
            }
            return(View(model));
        }
        public object Aprove(int id)
        {
            ParkingLotViewModel model = _parkingLotService.Get(id);

            if (model == null)
            {
                return(new ResponseDetails(false, $"Parking lot with Id : { model.Id } not found."));
            }

            model.IsAproved = true;

            _parkingLotService.Update(model);

            return(new ResponseDetails(true, "Parking lot Aproved successfully."));
        }
        public ActionResult EditParkingLot(ParkingLotViewModel model)
        {
            ParkingLot parkingLotEntity = parkingLotService.Get(model.Id);

            parkingLotEntity.Address      = model.Address;
            parkingLotEntity.CompanyName  = model.CompanyName;
            parkingLotEntity.ZipCode      = model.ZipCode;
            parkingLotEntity.ModifiedDate = DateTime.UtcNow;
            parkingLotService.Update(parkingLotEntity);

            if (parkingLotEntity.Id > 0)
            {
                return(RedirectToAction("index"));
            }
            return(View(model));
        }
        public object Add(ParkingLotViewModel model)
        {
            bool success = _userService.MakeOwner(model.OwnerId);

            if (success)
            {
                model = _parkingLotService.Add(model);

                if (model == null)
                {
                    return(new ResponseDetails(false, "Could not add new parking lot request."));
                }

                return(new ResponseDetails(true, model));
            }
            else
            {
                return(new ResponseDetails(false, $"User with Id : { model.OwnerId } not found."));
            }
        }
        public IActionResult Index()
        {
            List <ParkingLotViewModel> model = new List <ParkingLotViewModel>();

            parkingLotService.GetAll().ToList().ForEach(pl =>
            {
                ParkingLotViewModel parkingLot = new ParkingLotViewModel
                {
                    Id                           = pl.Id,
                    CompanyName                  = pl.CompanyName,
                    Address                      = pl.Address,
                    ZipCode                      = pl.ZipCode,
                    InitialNumberOfFloors        = pl.InitialNumberOfFloors,
                    InitialNumberOfSpotsPerFloor = pl.InitialNumberOfSpotsPerFloor,
                    ParkingFloors                = pl.ParkingFloors
                };

                model.Add(parkingLot);
            });

            return(View(model));
        }
示例#21
0
        public ParkingLotViewModel Add(ParkingLotViewModel model)
        {
            ParkingLot modelMapping = _mapper.Map <ParkingLot> (model);

            if (model.AddressViewModel != null)
            {
                modelMapping.Address = _mapper.Map <Address> (model.AddressViewModel);
            }

            if (model.SlotViewModels.Any())
            {
                modelMapping.Slots = _mapper.Map <List <Slot> > (model.SlotViewModels);
            }

            modelMapping.IsActive  = true;
            modelMapping.IsAproved = false;

            modelMapping = _unitOfWork.ParkingLotRepository.Add(modelMapping);
            _unitOfWork.SaveChanges();

            return(Get(modelMapping.Id));
        }
        public ActionResult AddParkingLot()
        {
            ParkingLotViewModel model = new ParkingLotViewModel();

            return(View(model));
        }
示例#23
0
 public void ProtectParkingLotRouteValues(ParkingLotViewModel model)
 {
     model.EncryptedId        = _dataProtector.Protect(model.Id.ToString());
     model.EncryptedOwnerId   = _dataProtector.Protect(model.OwnerId.ToString());
     model.EncryptedAddressId = _dataProtector.Protect(model.AddressId.ToString());
 }