Пример #1
0
        public IHttpActionResult GetAllUsers(int pageIndex, int pageSize, string type, bool editedFirst, bool approvedFirst)
        {
            RADBContext db          = new RADBContext();
            var         role        = db.Roles.SingleOrDefault(m => m.Name == type);
            var         usersByRole = db.Users.Include(x => x.AppUser).Where(m => m.Roles.All(r => r.RoleId == role.Id));

            List <AppUser> source = usersByRole.Select(x => x.AppUser).ToList();

            if (source == null || source.Count() < 1)
            {
                if (type == "AppUser")
                {
                    return(BadRequest("There are no Users"));
                }
                else
                {
                    return(BadRequest("There are no Managers"));
                }
            }


            if (editedFirst)
            {
                source = source.OrderByDescending(x => x.ProfileEdited).ToList();
            }
            else if (approvedFirst)
            {
                source = source.OrderByDescending(x => x.Activated).ToList();
            }


            // Get's No of Rows Count
            int count = source.Count();


            // Display TotalCount to Records to User
            int TotalCount = count;

            // Calculating Totalpage by Dividing (No of Records / Pagesize)
            int TotalPages = (int)Math.Ceiling(count / (double)pageSize);

            // Returns List of Customer after applying Paging
            var items = source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();


            // Object which we are going to send in header
            var paginationMetadata = new
            {
                totalCount = TotalCount,
                pageSize,
                currentPage = pageIndex,
                totalPages  = TotalPages
            };

            // Setting Header
            HttpContext.Current.Response.Headers.Add("Access-Control-Expose-Headers", "Paging-Headers");
            HttpContext.Current.Response.Headers.Add("Paging-Headers", JsonConvert.SerializeObject(paginationMetadata));

            return(Ok(items));
        }
Пример #2
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var allowedOrigin = "*";

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            ApplicationUserManager userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

            RAIdentityUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.!!!!");
                return;
            }

            RADBContext db = new RADBContext();



            string fullName = db.AppUsers.SingleOrDefault(r => r.UserId == user.AppUserId).FullName;


            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, "JWT");

            oAuthIdentity.AddClaim(new Claim("UserFullName", fullName));
            var ticket = new AuthenticationTicket(oAuthIdentity, null);

            context.Validated(ticket);
        }
Пример #3
0
        public ResponceLogin GetLogin(string email, string password)
        {
            RADBContext context = new RADBContext();
            User        user    = context._Users.FirstOrDefault(x => email == x.Email);

            if (user == default(User))
            {
                return(new ResponceLogin {
                    responce = 1
                });
            }
            if (LogedIn.Contains(user.Email))
            {
                return(new ResponceLogin {
                    responce = 2
                });
            }
            if (user.Password == password)
            {
                LogedIn.Add(email);
                return(new ResponceLogin {
                    responce = 3, user = user
                });
            }
            else
            {
                return(new ResponceLogin {
                    responce = 4
                });
            }
        }
Пример #4
0
        public IEnumerable <Service> GetAll(int pageIndex, int pageSize)
        {
            RADBContext    db       = new RADBContext();
            List <Service> services = new List <Service>(db.Services);

            services = new List <Service>(services.OrderBy(s => s.Name).Skip((pageIndex - 1) * pageSize).Take(pageSize));

            return(services);
        }
Пример #5
0
        public IEnumerable <Vehicle> GetAll(int pageIndex, int pageSize)
        {
            RADBContext    db      = new RADBContext();
            List <Vehicle> vehicle = new List <Vehicle>(db.Vehicles);

            vehicle = new List <Vehicle>(vehicle.OrderBy(s => s.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize));

            return(vehicle);
        }
        public IHttpActionResult GetCurrentAppUser()
        {
            var username = User.Identity.Name;

            RADBContext db      = new RADBContext();
            var         user    = db.Users.Where(u => u.UserName == username).Include(u1 => u1.AppUser).First();
            var         appUser = user.AppUser;

            return(Ok(appUser));
        }
Пример #7
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);
        }
Пример #8
0
        public int PostNewService(Service service)
        {
            if (service == null)
            {
                return(1);
            }
            RADBContext context = new RADBContext();

            context.Services.Add(service);
            context.SaveChanges();
            return(0);
        }
Пример #9
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);
        }
Пример #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 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);
        }
Пример #12
0
        public IEnumerable <Reservation> GetReservations(Guid id)
        {
            RADBContext context      = new RADBContext();
            List <Guid> reservations = new List <Guid>();

            return(context._Users
                   .Include(x => x.Reservations)
                   .Include(x => x.Reservations.Select(q => q.Service))
                   .Include(x => x.Reservations.Select(q => q.StartBranchOffice))
                   .Include(x => x.Reservations.Select(q => q.Vehicle))
                   .Include(x => x.Reservations.Select(q => q.EndBranchOffice))
                   .FirstOrDefault(x => x.Id.CompareTo(id) == 0).Reservations);
        }
Пример #13
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);
        }
Пример #14
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var allowedOrigin = "*";

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            ApplicationUserManager userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

            RAIdentityUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.!!!!");
                return;
            }
            RADBContext db = new RADBContext();

            var userRole = user.Roles.FirstOrDefault();
            var role     = db.Roles.SingleOrDefault(r => r.Id == userRole.RoleId);
            var roleName = role?.Name;

            if (roleName == "Admin")
            {
                context.OwinContext.Response.Headers.Add("Role", new[] { "Admin" });
            }
            else if (roleName == "Manager")
            {
                context.OwinContext.Response.Headers.Add("Role", new[] { "Manager" });
            }
            else
            {
                context.OwinContext.Response.Headers.Add("Role", new[] { "User" });
            }

            //Mora se dodati u header response-a kako bi se se Role atribut
            //mogao procitati na klijentskoj strani
            context.OwinContext.Response.Headers.Add("Access-Control-Expose-Headers", new[] { "Role" });


            //if (!user.EmailConfirmed)
            //{
            //    context.SetError("invalid_grant", "AppUser did not confirm email.");
            //    return;
            //}

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, "JWT");

            var ticket = new AuthenticationTicket(oAuthIdentity, null);

            context.Validated(ticket);
        }
Пример #15
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);
        }
Пример #16
0
 public CountryController(DbContext context)
 {
     db = context as RADBContext;
 }
Пример #17
0
 public ServicesController(DbContext context)
 {
     db = context as RADBContext;
 }
Пример #18
0
 public CommentController(DbContext context)
 {
     db = context as RADBContext;
 }
Пример #19
0
 public AppUserController(DbContext context)
 {
     db = context as RADBContext;
 }
Пример #20
0
        public IEnumerable <Service> GetUnaprovedServices()
        {
            RADBContext context = new RADBContext();

            return(context.Services.Where(x => !x.Aproved).ToArray());
        }
Пример #21
0
        public IEnumerable <BranchOffice> GetBrancheOffices(Guid id)
        {
            RADBContext context = new RADBContext();

            return(context.Services.Include(x => x.BranchOffices).First(x => x.Id.CompareTo(id) == 0).BranchOffices);
        }
 public long Count()
 {
     return(RADBContext.Set <AccountForApprove>().Count());
 }
Пример #23
0
        public IEnumerable <Vehicle> GetVehicles(Guid id)
        {
            RADBContext context = new RADBContext();

            return(context.BrancheOffices.Include(x => x.Vehicles).First(x => x.Id.CompareTo(id) == 0).Vehicles);
        }
Пример #24
0
        public IEnumerable <User> GetUnaprovedUsers()
        {
            RADBContext context = new RADBContext();

            return(context._Users.Where(x => !x.Approved));
        }
Пример #25
0
 public LocationController(DbContext context)
 {
     db = context as RADBContext;
 }
Пример #26
0
 public CarController(DbContext context)
 {
     db = context as RADBContext;
 }
 public DriverController(DbContext context, ApplicationUserManager userManager)
 {
     UserManager = userManager;
     db          = context as RADBContext;
 }
Пример #28
0
        public IHttpActionResult AddRentService()
        {
            RADBContext db = new RADBContext();
            AppUser     appUser;

            try
            {
                var username = User.Identity.Name;

                var user = _unitOfWork.AppUsers.Find(u => u.Email == username).FirstOrDefault();
                if (user == null)
                {
                    return(BadRequest("Data could not be retrieved, try to relog."));
                }
                appUser = user;
            }
            catch
            {
                return(BadRequest("User not found, try to relog"));
            }

            if (appUser == null)
            {
                return(BadRequest("Try to relog"));
            }

            if (appUser.Activated == false)
            {
                return(BadRequest("You can't add new Rent Services right now"));
            }

            var httpRequest = HttpContext.Current.Request;

            string imageName = null;



            RentService service = new RentService();

            service.Name          = httpRequest["Name"].Trim();
            service.Description   = httpRequest["Description"].Trim();
            service.Email         = httpRequest["Email"].Trim();
            service.Activated     = false;
            service.ServiceEdited = true;
            service.UserId        = appUser.UserId;


            if (service.Logo == null || service.Logo == "")
            {
                var postedFile = httpRequest.Files["Logo"];
                imageName = new string(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-");
                imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
                var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName);
                postedFile.SaveAs(filePath);
                service.Logo = imageName;
            }

            try
            {
                _unitOfWork.RentServices.Add(service);
                _unitOfWork.Complete();

                appUser.RentServices.Add(service);
                _unitOfWork.AppUsers.Update(appUser);
                _unitOfWork.Complete();
            }
            catch
            {
                return(BadRequest("Rent Service could not be added"));
            }
            NotificationsHub.NotifyAdmin("New Rent Service was added");

            return(Created("Rent Service was created", service));
        }
 public DriveController(DbContext context)
 {
     db = context as RADBContext;
 }
 public VehicleTypeController(DbContext context)
 {
     db = context as RADBContext;
 }