Exemplo n.º 1
0
        public IActionResult login(LocationUser newuser)
        {
            var newUser = OrderViewModel.GetUserByName(newuser.Name);

            if (newUser == null)
            {
                if (newuser.password == newuser.secondary)
                {
                    var domuser = new dom.User()
                    {
                        name = newuser.Name, password = newuser.password
                    };
                    UserHelper.SetUser(domuser);
                    ViewData["name"] = newuser.Name;
                    return(View("Welcome"));
                }
                else
                {
                    ViewData["ErrorMessage"] = "Passwords don't match";
                    return(View("SignUp"));
                }
            }

            ViewData["name"] = newuser.Name;
            return(View("userexists"));
        }
Exemplo n.º 2
0
        public static int SetOrder(dom.Order r)
        {
            var _db    = new PizzaStoreDbContext();
            var loc    = _db.Location.Where(l => l.LocationId == r.StoreID).FirstOrDefault();
            var myuser = _db.User.Where(u => u.UserId == r.UserID).FirstOrDefault();

            if (loc == null || myuser == null)
            {
                return(0);
            }
            else
            {
                var dataorder = new Order()
                {
                    Cost        = (decimal)r.Cost()
                    , StoreId   = r.StoreID
                    , Voidable  = r.Voidable
                    , TimeStamp = DateTime.Now
                    , UserId    = r.UserID
                };

                var locuserpair = new LocationUser()
                {
                    LocationId = loc.LocationId,
                    UserId     = myuser.UserId
                };

                _db.LocationUser.Add(locuserpair);
                _db.Order.Add(dataorder);
                return(_db.SaveChanges());
            }
        }
Exemplo n.º 3
0
        public async Task <LocationUser> AddLocationUserList(LocationUser location)
        {
            var locationsUserlists = await GetAllLocationUserlists();

            locationsUserlists.Add(location);
            SaveLocationsUserToJsonFile(locationsUserlists);
            return(await GetLocationUserList(location.Id));
        }
Exemplo n.º 4
0
        public async Task DeleteLocationUser(LocationUser locationUser)
        {
            using (DataContext = new SimplySecureDataContext())
            {
                DataContext.LocationUsers.Remove(locationUser);

                await DataContext.SaveChangesAsync();
            }
        }
        /// Called whenever the page is navigated to.
        /// </summary>
        /// <param name="initData"></param>
        public async override void Init(object initData)
        {
            base.Init(initData);

            _currentLocationUser = initData as LocationUser;


            await RefreshLocationUser();
        }
Exemplo n.º 6
0
        public async Task CreateLocationUser(Location location, ApplicationUser user)
        {
            var locationUser
                = new LocationUser
                {
                LocationId        = location.Id,
                ApplicationUserId = user.Id
                };

            await CreateLocationUser(locationUser);
        }
Exemplo n.º 7
0
        public ActionResult ChooseLocation()
        {
            var locationuser = new LocationUser();

            locationuser.AvailableLocations = locationuser.GetLocations();
            if (HttpContext.Session.GetString("LocationError") != null)
            {
                ViewData["LocationError"] = HttpContext.Session.GetString("LocationError");
                HttpContext.Session.Remove("LocationError");
            }
            return(View("ChooseLocation", locationuser));
        }
Exemplo n.º 8
0
 public ActionResult CheckLocation(LocationUser mylocation)
 {
     if (mylocation.StoreId == 0)
     {
         HttpContext.Session.SetString("LocationError", "Location needs to be picked!");
         return(RedirectToAction("ChooseLocation", "Order"));
     }
     else
     {
         return(StartOrder(mylocation.StoreId));
     }
 }
Exemplo n.º 9
0
        public async Task CreateLocationUser(LocationUser locationUser)
        {
            using (DataContext = new SimplySecureDataContext())
            {
                DataContext.LocationUsers.RemoveRange
                    (DataContext.LocationUsers.Where(u => u.ApplicationUserId == locationUser.ApplicationUserId &&
                                                     u.LocationId == locationUser.LocationId));

                DataContext.LocationUsers.Add(locationUser);

                await DataContext.SaveChangesAsync();
            }
        }
        private bool Validate(LocationUser location)
        {
            var validationResult = _locationUserValidator.Validate(location);

            //loop through error to identify properties
            foreach (var error in validationResult.Errors)
            {
                if (error.PropertyName == nameof(location.Name))
                {
                    LocationUserNameError = error.ErrorMessage;
                }
            }
            return(validationResult.IsValid);
        }
Exemplo n.º 11
0
        public async Task <InvokeResult> AddUserToLocationAsync(String userId, String locationId, EntityHeader org, EntityHeader addedBy)
        {
            await AuthorizeOrgAccessAsync(addedBy, org, typeof(LocationUser), Actions.Create, new SecurityHelper { UserId = userId, LocationId = locationId });

            var appUser = await _appUserRepo.FindByIdAsync(userId);

            var location = await _locationRepo.GetLocationAsync(locationId);

            var locationUser = new LocationUser(location.Organization.Id, locationId, userId)
            {
                UsersName = appUser.Name
            };

            await _locationUserRepo.AddUserToLocationAsync(locationUser);

            return(InvokeResult.Success);
        }
Exemplo n.º 12
0
        public ActionResult ViewOrders()
        {
            var enteredUser = new LocationUser()
            {
                Name = HttpContext.Session.GetString("ActiveUser")
            };

            dat.PizzaStoreDbContext _db = new dat.PizzaStoreDbContext();
            var dataUser = _db.User.Where(u => u.Name == enteredUser.Name).FirstOrDefault();

            enteredUser.History = UserHelper.GetOrdersByUser(dataUser);
            enteredUser.AssignCrusts();

            ViewData["name"] = enteredUser.Name;

            return(View("ViewOrders", enteredUser));
        }
        public async Task CreateLocation(ILocationUsersRepository locationUsersRepository, Location location)
        {
            using (DataContext = new SimplySecureDataContext())
            {
                DataContext.Locations.Add(location);

                await DataContext.SaveChangesAsync();

                var locationUser = new LocationUser
                {
                    LocationId = location.Id,

                    ApplicationUserId = location.ApplicationUserId
                };

                await locationUsersRepository.CreateLocationUser(locationUser);
            }
        }
Exemplo n.º 14
0
        public IActionResult loguserin(LocationUser enteredUser)
        {
            dat.PizzaStoreDbContext _db = new dat.PizzaStoreDbContext();
            var dataUser = _db.User.Where(u => u.Name == enteredUser.Name).FirstOrDefault();

            if (dataUser == null)
            {
                HttpContext.Session.SetString("UserError", "Your username is not found.");
                return(RedirectToAction("SignUp", "Home"));
            }

            if (dataUser.Password != enteredUser.password)
            {
                ViewData["ErrorMessage"] = "Passwords don't match";
                return(View("signIn"));
            }

            HttpContext.Session.SetString("ActiveUser", dataUser.Name);
            return(View("Index"));
        }
 /// <summary>
 /// Refreshes the currentlocationuser (to edit) or initializes a new one (to add)
 /// </summary>
 /// <returns></returns>
 private async Task RefreshLocationUser()
 {
     if (_currentLocationUser != null)
     {
         //editing existing locationlist
         isNew                = false;
         PageTitle            = "Edit Location List";
         _currentLocationUser = await locationUserRepository.GetLocationUserList(_currentLocationUser.Id);
     }
     else
     {
         //editing brand new locationlist
         isNew                      = true;
         PageTitle                  = "New Location List";
         _currentLocationUser       = new LocationUser();
         _currentLocationUser.Id    = Guid.NewGuid();
         _currentLocationUser.Items = new List <LocationItem>();
     }
     LoadLocationUserState();
 }
Exemplo n.º 16
0
        public async Task <LocationUser> UpdateLocationUserList(LocationUser location)
        {
            await DeleteLocationUserList(location.Id);

            return(await AddLocationUserList(location));
        }
Exemplo n.º 17
0
        public HttpResponseMessage UserDetails(int userId, string ClientId = "")
        {
            //var isCustomer=  HttpContext.Current.Request.Params["IsCustomer"];
            if (ClientId == "User")
            {
                //PasswordHasher pass = new PasswordHasher();
                //var hashedPassword = EncodePassword(context.Password, MembershipPasswordFormat.Hashed, "MAKV2SPBNI99212");
                var user = db.Users.Where(x => x.UserId == userId).FirstOrDefault();
                // password is correct


                //var userManager = context.OwinContext.GetUserManager<Loader.UserManager>();
                // var user = await userManager.FindAsync(context.UserName, context.Password);

                //Loader.Models.ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
                if (user != null && user.IsActive == true)
                {
                    if (user.UserDesignationId == 11)
                    {
                        var locations = String.Format("select  locationid from  fgetlocationlistbycollector('" + user.UserId + "')");


                        List <int> returnData = db.Database.SqlQuery <int>(locations).ToList();
                        int[]      myintlist  = returnData.ToArray();



                        var sul = new LocationUser
                        {
                            EmployeeId        = user.EmployeeId,
                            Email             = user.Email,
                            UserId            = user.UserId,
                            UserName          = user.UserName,
                            EffDate           = user.EffDate,
                            TillDate          = user.TillDate,
                            MTId              = user.MTId,
                            IsUnlimited       = user.IsUnlimited,
                            UserDesignationId = user.UserDesignationId,
                            Location          = myintlist,
                        };

                        return(Request.CreateResponse(HttpStatusCode.OK, sul, Configuration.Formatters.JsonFormatter));
                        //return Ok(new { results = sul });
                    }
                    else
                    {
                        var sul = new LocationUser
                        {
                            EmployeeId        = user.EmployeeId,
                            Email             = user.Email,
                            UserId            = user.UserId,
                            UserName          = user.UserName,
                            EffDate           = user.EffDate,
                            TillDate          = user.TillDate,
                            MTId              = user.MTId,
                            IsUnlimited       = user.IsUnlimited,
                            UserDesignationId = user.UserDesignationId
                        };
                        //return Ok(new { results = sul });

                        return(Request.CreateResponse(HttpStatusCode.OK, sul, Configuration.Formatters.JsonFormatter));
                    }
                }

                //Logger.writeLog(Request, Logger.JsonDataResult(sul), Logger.JsonDataResult(context));



                else if (user != null && user.IsActive == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid User", Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "User Not Found ", Configuration.Formatters.JsonFormatter));
                }
            }

            else if (ClientId == "Customer")
            {
                //var hashedPassword = EncodePassword(context.Password, MembershipPasswordFormat.Hashed, "MAKV2SPBNI99212");
                var user = db.CustomerUserTables.Where(x => x.UserId == userId).FirstOrDefault();

                //CustomerUser user = db.CustomerUsers.Where(x => x.UserName == context.UserName).FirstOrDefault();

                if (user != null && user.IsActive == true)
                {
                    var sul = new customerUser
                    {
                        CustomerId  = user.CustomerId,
                        Email       = user.Email,
                        UserId      = user.UserId,
                        UserName    = user.UserName,
                        EffDate     = user.EffDate,
                        TillDate    = user.TillDate,
                        MTId        = user.MTId,
                        IsUnlimited = user.IsUnlimited
                    };
                    //Logger.writeLog(Request, Logger.JsonDataResult(sul), Logger.JsonDataResult(context));
                    //return Ok(new { results = sul });

                    return(Request.CreateResponse(HttpStatusCode.OK, sul, Configuration.Formatters.JsonFormatter));
                }
                else if (user != null && user.IsActive == false)
                {
                    //return BadRequest("Customer Not Active");
                    return(Request.CreateResponse(HttpStatusCode.Unauthorized, "User Not Active", Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "User Not Found", Configuration.Formatters.JsonFormatter));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "User Not Found", Configuration.Formatters.JsonFormatter));
            }
        }
Exemplo n.º 18
0
        public async Task <IHttpActionResult> PostLogin([FromBody] OAuthGrantResourceOwnerCredentialsContext context)
        {
            //var isCustomer=  HttpContext.Current.Request.Params["IsCustomer"];
            if (context.ClientId == "User")
            {
                PasswordHasher pass = new PasswordHasher();
                //var hashedPassword = EncodePassword(context.Password, MembershipPasswordFormat.Hashed, "MAKV2SPBNI99212");
                var user = db.Users.Where(x => x.UserName == context.UserName.Trim()).FirstOrDefault();
                // password is correct


                //var userManager = context.OwinContext.GetUserManager<Loader.UserManager>();
                // var user = await userManager.FindAsync(context.UserName, context.Password);

                //Loader.Models.ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
                if (user != null && user.IsActive == true && pass.VerifyHashedPassword(user.PasswordHash, context.Password) != PasswordVerificationResult.Failed)
                {
                    if (user.UserDesignationId == 11)
                    {
                        var locations = String.Format("select  locationid from  fgetlocationlistbycollector('" + user.UserId + "')");


                        List <int> returnData = db.Database.SqlQuery <int>(locations).ToList();
                        int[]      myintlist  = returnData.ToArray();



                        var sul = new LocationUser
                        {
                            EmployeeId        = user.EmployeeId,
                            Email             = user.Email,
                            UserId            = user.UserId,
                            UserName          = user.UserName,
                            EffDate           = user.EffDate,
                            TillDate          = user.TillDate,
                            MTId              = user.MTId,
                            IsUnlimited       = user.IsUnlimited,
                            UserDesignationId = user.UserDesignationId,
                            Location          = myintlist
                        };
                        return(Ok(new { results = sul }));
                    }
                    else
                    {
                        var sul = new User
                        {
                            EmployeeId        = user.EmployeeId,
                            Email             = user.Email,
                            UserId            = user.UserId,
                            UserName          = user.UserName,
                            EffDate           = user.EffDate,
                            TillDate          = user.TillDate,
                            MTId              = user.MTId,
                            IsUnlimited       = user.IsUnlimited,
                            UserDesignationId = user.UserDesignationId,
                        };
                        return(Ok(new { results = sul }));
                    }
                }

                //Logger.writeLog(Request, Logger.JsonDataResult(sul), Logger.JsonDataResult(context));



                else if (user != null && user.IsActive == false)
                {
                    return(BadRequest("User Not Active"));
                }
                else
                {
                    return(NotFound());
                }
            }

            else if (context.ClientId == "Customer")
            {
                PasswordHasher pass = new PasswordHasher();
                //var hashedPassword = EncodePassword(context.Password, MembershipPasswordFormat.Hashed, "MAKV2SPBNI99212");
                var user = db.CustomerUserTables.Where(x => x.UserName == context.UserName).FirstOrDefault();

                //CustomerUser user = db.CustomerUsers.Where(x => x.UserName == context.UserName).FirstOrDefault();

                if (user != null && user.IsActive == true && pass.VerifyHashedPassword(user.PasswordHash, context.Password) != PasswordVerificationResult.Failed)
                {
                    var sul = new CustomerUserTable
                    {
                        CustomerId  = user.CustomerId,
                        Email       = user.Email,
                        UserId      = user.UserId,
                        UserName    = user.UserName,
                        EffDate     = user.EffDate,
                        TillDate    = user.TillDate,
                        MTId        = user.MTId,
                        IsUnlimited = user.IsUnlimited,
                    };
                    //Logger.writeLog(Request, Logger.JsonDataResult(sul), Logger.JsonDataResult(context));
                    return(Ok(new { results = sul }));
                }
                else if (user != null && user.IsActive == false)
                {
                    return(BadRequest("Customer Not Active"));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(NotFound());
            }
        }