示例#1
0
        public IHttpActionResult PutAppUser(int id, AppUser appUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != appUser.Id)
            {
                return(BadRequest());
            }

            db.Entry(appUser).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutTypeOfVehicle(int id, TypeOfVehicle typeOfVehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != typeOfVehicle.Id)
            {
                return(BadRequest());
            }

            db.Entry(typeOfVehicle).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TypeOfVehicleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult AddDrive()
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Drive drive = new Drive();
            var httpRequest = HttpContext.Current.Request;

            try
            {
                drive = JsonConvert.DeserializeObject<Drive>(httpRequest.Form[0]);
                if(drive.DriverId != null)
                {
                    Driver user = (Driver)db.AppUsers
                               .Where(b => b.Id == drive.DriverId)
                               .FirstOrDefault();

                    user.Available = false;
                    db.Entry(user).State = EntityState.Modified;
                }
            }
            catch (JsonSerializationException)
            {
                return BadRequest(ModelState);
            }

            db.Drives.Add(drive);

            try
            {

                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return BadRequest(ModelState);
            }
            catch (DbUpdateException)
            {
                return BadRequest(ModelState);
            }

            return Ok("Success");
        }
示例#4
0
        public IHttpActionResult ChangeUser(RegisterBindingModel user)
        {
            RAIdentityUser RAuser2change = db.Users
                                           .Where(b => b.UserName == user.Username)
                                           .FirstOrDefault();

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

            AppUser user2change = db.AppUsers
                                  .Where(b => b.Id == RAuser2change.AppUserId)
                                  .FirstOrDefault();

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


            user2change.ContactNumber  = user.ContactNumber;
            user2change.DriveType      = user.DriveType;
            user2change.Email          = user.Email;
            user2change.FullName       = user.FullName;
            user2change.Gender         = user.Gender;
            user2change.DriveType      = user.DriveType;
            RAuser2change.PasswordHash = RAIdentityUser.HashPassword(user.Password);

            try
            {
                db.Entry(user2change).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok(user2change));
        }
        public async Task <IHttpActionResult> AddDriver()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Driver driver      = new Driver();
            var    httpRequest = HttpContext.Current.Request;

            try
            {
                driver = JsonConvert.DeserializeObject <Driver>(httpRequest.Form[0]);
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            var user = new RAIdentityUser()
            {
                Id = driver.Username, UserName = driver.Username, Email = driver.Email, AppUser = driver, PasswordHash = RAIdentityUser.HashPassword(driver.PasswordLogin)
            };

            db.AppUsers.Add(driver);
            IdentityResult result = await UserManager.CreateAsync(user);

            UserManager.AddToRole(user.Id, driver.Role.ToString());

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok());
        }
示例#6
0
        public int PostNewUser(User user)
        {
            RADBContext context = new RADBContext();

            if (context._Users.FirstOrDefault(x => x.Email == user.Email) != default(User))
            {
                return(0);
            }
            context._Users.Add(user);
            context.SaveChanges();
            return(1);
        }
示例#7
0
        public int PostNewService(Service service)
        {
            if (service == null)
            {
                return(1);
            }
            RADBContext context = new RADBContext();

            context.Services.Add(service);
            context.SaveChanges();
            return(0);
        }
示例#8
0
        public int PostReservationForUser(Guid id, Reservation reservation)
        {
            RADBContext context = new RADBContext();
            User        u       = context._Users.Include(x => x.Reservations).FirstOrDefault(x => x.Id.CompareTo(id) == 0);

            if (u == default(User))
            {
                return(1);
            }
            u.Reservations.Add(reservation);
            context.SaveChanges();
            return(0);
        }
示例#9
0
        public int PostBranchOffice(Guid id, BranchOffice branchOffice)
        {
            RADBContext context = new RADBContext();
            Service     ser     = context.Services.Include(x => x.BranchOffices).First(x => x.Id.CompareTo(id) == 0);

            if (ser == default(Service))
            {
                return(-1);
            }
            ser.BranchOffices.Add(branchOffice);
            context.SaveChanges();
            return(0);
        }
示例#10
0
        public int PostVehicle(Guid id, Vehicle vehicle)
        {
            RADBContext  context = new RADBContext();
            BranchOffice bo      = context.BrancheOffices.Include(x => x.Vehicles).FirstOrDefault(x => x.Id.CompareTo(id) == 0);

            if (bo == default(BranchOffice))
            {
                return(-1);
            }
            bo.Vehicles.Add(vehicle);
            context.SaveChanges();
            return(0);
        }
示例#11
0
        public int PostAproveNewService(Service ser)
        {
            RADBContext context = new RADBContext();
            Service     s       = context.Services.FirstOrDefault(x => x.Id.CompareTo(ser.Id) == 0);

            if (s == default(Service))
            {
                return(0);
            }
            s.Aproved = true;
            context.SaveChanges();
            return(1);
        }
        public IHttpActionResult PostVehicle()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Vehicle newVehicle  = new Vehicle();
            var     httpRequest = HttpContext.Current.Request;

            try
            {
                newVehicle             = JsonConvert.DeserializeObject <Vehicle>(httpRequest.Form[0]);
                newVehicle.Service     = db.Services.Find(newVehicle.ServiceId);
                newVehicle.VehicleType = db.VehicleTypes.Find(newVehicle.VehicleTypeId);
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            db.Vehicles.Add(newVehicle);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok("Success"));
        }
        public IHttpActionResult ChangeManagerStatus()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AppUser changeUser = null;
            int     id;
            var     httpRequest = HttpContext.Current.Request;

            try
            {
                id         = JsonConvert.DeserializeObject <Int32>(httpRequest.Form[0]);
                changeUser = db.AppUsers.Find(id);
                changeUser.CanCreateService = (changeUser.CanCreateService == true) ? false : true;
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                db.Entry(changeUser).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok("Success"));
        }
示例#14
0
        public int PostAproveNewUser(User user)
        {
            if (user.Id == null)
            {
                return(2);
            }
            RADBContext context = new RADBContext();
            User        u       = context._Users.FirstOrDefault(x => x.Id == user.Id);

            if (u == default(User))
            {
                return(0);
            }
            u.Approved = true;
            context.SaveChanges();
            return(1);
        }
示例#15
0
        public IHttpActionResult AddComment()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Comment comment     = new Comment();
            var     httpRequest = HttpContext.Current.Request;

            try
            {
                comment = JsonConvert.DeserializeObject <Comment>(httpRequest.Form[0]);
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            Drive drive = db.Drives.Where(d => d.Id == comment.DriveId)
                          .FirstOrDefault();

            drive.CommentId = comment.Id;

            db.Comments.Add(comment);

            try
            {
                db.Entry(drive).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok("Success"));
        }
示例#16
0
        public IHttpActionResult AddCar()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Car car         = new Car();
            var httpRequest = HttpContext.Current.Request;

            try
            {
                car = JsonConvert.DeserializeObject <Car>(httpRequest.Form[0]);
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            db.Cars.Add(car);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok("Success"));
        }
示例#17
0
        public IHttpActionResult AddLocation()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Location location    = new Location();
            var      httpRequest = HttpContext.Current.Request;

            try
            {
                location = JsonConvert.DeserializeObject <Location>(httpRequest.Form[0]);
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            db.Locations.Add(location);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(BadRequest(ModelState));
            }
            catch (DbUpdateException)
            {
                return(BadRequest(ModelState));
            }

            return(Ok("Success"));
        }
示例#18
0
        public IHttpActionResult ChangeVehiclePrice()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var           httpRequest         = HttpContext.Current.Request;
            PriceListItem newPriceListItem    = new PriceListItem();
            PriceListItem changePriceListItem = null;

            try
            {
                newPriceListItem = JsonConvert.DeserializeObject <PriceListItem>(httpRequest.Form[0]);
            }
            catch (JsonSerializationException)
            {
                return(BadRequest(ModelState));
            }

            foreach (PriceListItem pi in db.PriceListItems)
            {
                if (pi.VehicleId == newPriceListItem.VehicleId)
                {
                    changePriceListItem = pi;
                    break;
                }
            }

            if (changePriceListItem != null)
            {
                try
                {
                    changePriceListItem.Price = newPriceListItem.Price;
                }
                catch (JsonSerializationException)
                {
                    return(BadRequest(ModelState));
                }

                try
                {
                    db.Entry(changePriceListItem).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (DbEntityValidationException)
                {
                    return(BadRequest(ModelState));
                }
                catch (DbUpdateException)
                {
                    return(BadRequest(ModelState));
                }
            }
            else
            {
                try
                {
                    newPriceListItem.Vehicle = db.Vehicles.Find(newPriceListItem.VehicleId);
                }
                catch (JsonSerializationException)
                {
                    return(BadRequest(ModelState));
                }

                db.PriceListItems.Add(newPriceListItem);

                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException)
                {
                    return(BadRequest(ModelState));
                }
                catch (DbUpdateException)
                {
                    return(BadRequest(ModelState));
                }
            }

            return(Ok("Success"));
        }