Exemplo n.º 1
0
        public IActionResult Put(int id, ParkingProfileViewModel model)
        {
            if (id == 0 && model == null)
            {
                return(null);
            }

            var parking = _dbContext.parkings
                          .FirstOrDefault(p => p.ParkingId == id);
            var facilities = _dbContext.ParkingFacilities
                             .FirstOrDefault(p => p.Parking.ParkingId == parking.ParkingId);

            if (parking == null)
            {
                return(NotFound());
            }



            parking.Name        = model.Name;
            parking.Description = model.Description;
            parking.City        = model.City;
            parking.Address     = model.Address;

            var result = _dbContext.Update(parking);

            if (_dbContext.SaveChanges() > 0)
            {
                if (facilities == null)
                {
                    var facility = new ParkingFacilities()
                    {
                        Parking        = parking,
                        GuestRoom      = model.GuestRoom,
                        OnlinePayment  = model.OnlinePayment,
                        ServiceStation = model.ServiceStation
                    };

                    _dbContext.Add(facilities);
                    _dbContext.SaveChanges();
                }
                else
                {
                    facilities.ServiceStation = model.ServiceStation;
                    facilities.OnlinePayment  = model.OnlinePayment;
                    facilities.GuestRoom      = model.GuestRoom;
                    _dbContext.Update(facilities);
                    _dbContext.SaveChanges();
                }
            }


            return(Ok());
        }
Exemplo n.º 2
0
        public IActionResult Get()
        {
            string imgsrc = null;
            ParkingProfileViewModel model = new ParkingProfileViewModel();
            var userId     = _caller.Claims.Single(c => c.Type == "id");
            var OnlineUser = _userManager.FindByIdAsync(userId.Value).Result;

            var parking     = _dbContext.parkings.FirstOrDefault(p => p.appUser.Id == OnlineUser.Id);
            var slotCount   = _dbContext.slots.Where(p => p.Parking.ParkingId == parking.ParkingId).Count();
            var faicilities = _dbContext.ParkingFacilities.Include(p => p.Parking)
                              .FirstOrDefault(p => p.Parking.ParkingId == parking.ParkingId);

            if (parking.ParkImage != null)
            {
                var base64 = Convert.ToBase64String(parking.ParkImage);
                imgsrc = string.Format("data:image/gif;base64,{0}", base64);
            }


            if (faicilities != null)
            {
                model.GuestRoom      = faicilities.GuestRoom;
                model.OnlinePayment  = faicilities.OnlinePayment;
                model.ServiceStation = faicilities.ServiceStation;
            }


            model.Id          = parking.ParkingId;
            model.PhoneNo     = OnlineUser.PhoneNumber;
            model.NoOfSlot    = slotCount;
            model.Email       = OnlineUser.Email;
            model.Description = parking.Description;
            model.City        = parking.City;
            model.Address     = parking.Address;
            model.Name        = parking.Name;

            if (imgsrc != null)
            {
                model.Image = imgsrc;
            }

            return(new OkObjectResult(model));
        }