Beispiel #1
0
 public IActionResult UserAdd(UserRestaurant res)
 {
     if (ModelState.IsValid)
     {
         TempStorage.AddApp(res);
         return(RedirectToAction("UserList"));
     }
     return(View());
 }
        public IActionResult AddRestaurant(UserRestaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                TempStorage.AddRestaurant(restaurant);
                List <UserRestaurant> allRestaurants = TempStorage.UserRestaurants.ToList();
                return(View("ViewUserRestaurants", allRestaurants));
            }

            return(View());
        }
Beispiel #3
0
        public IActionResult AddRestaurant(int userId, UserRestaurant restaurantToAddToProfile)
        {
            var existingUserRestaurant = _UserRepository.GetSingleUserRestaurantByUserId(userId, restaurantToAddToProfile.RestaurantId);

            if (existingUserRestaurant == null)
            {
                var result = _UserRepository.AddRestaurantToProfile(restaurantToAddToProfile);
                return(Ok(result));
            }
            return(Ok(existingUserRestaurant));
        }
Beispiel #4
0
        public UserRestaurant AddRestaurantToProfile(UserRestaurant restaurantToAddToProfile)
        {
            var sql = @"insert into UserRestaurant (UserId, RestaurantId)
                        output inserted.*
                        values(@UserId, @RestaurantId)";

            using (var db = new SqlConnection(ConnectionString))
            {
                var result = db.QueryFirstOrDefault <UserRestaurant>(sql, restaurantToAddToProfile);
                return(result);
            }
        }
        public IActionResult RestaurantForm(UserRestaurant userRest)
        {
            if (ModelState.IsValid)
            {
                TempStorage.AddRestaurantToList(userRest);
                return(View("Confirm", userRest));
            }

            else
            {
                return(View());
            }
        }
Beispiel #6
0
        public IActionResult AddRestaurants(UserRestaurant appResponse)
        {
            //Default value for null or empty Favorite Dish
            if (String.IsNullOrEmpty(appResponse.FavoriteDish))
            {
                appResponse.FavoriteDish = "It's all tasty!";
            }

            //adds apppResponse data to TempStorage
            TempStorage.AddApplication(appResponse);

            //Passes in form data
            return(View("Confirmation", appResponse));
        }
Beispiel #7
0
 public IActionResult Submit(UserRestaurant response)
 {
     //Check validation
     if (ModelState.IsValid)
     {
         //Add to list of restaurant objects
         Storage.AddRestaurant(response);
         //Go to confirmation page
         return(View("Confirmation"));
     }
     else
     {
         //Don't leave the page if responses are invalid
         return(View());
     }
 }
Beispiel #8
0
        public async Task <string> PostUserRestaurant(UserRestaurant userRestaurant)
        {
            var restaurant = await _context.UserRestaurant
                             .Where(u => u.Iduser == userRestaurant.Iduser && u.Idrestaurant == userRestaurant.Idrestaurant).FirstOrDefaultAsync();

            if (restaurant == null)
            {
                _context.UserRestaurant.Add(userRestaurant);
                await _context.SaveChangesAsync();
            }
            else
            {
                restaurant.Favorite = true;
                _context.UserRestaurant.Update(restaurant);
                await _context.SaveChangesAsync();
            }
            return("Restaurante agregado a favoritos");
        }
Beispiel #9
0
        public async Task <string> AddToFavoriteAsync(int idRes)
        {
            UserRestaurant user = new UserRestaurant();

            user.idrestaurant = idRes;
            user.iduser       = Preferences.Get("idUser", 0);
            user.favorite     = true;

            HttpClient client = new HttpClient();

            client = BaseClient(client);

            var content     = JsonConvert.SerializeObject(user);
            var byteContent = new ByteArrayContent(Encoding.UTF8.GetBytes(content));

            byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
            var response = client.PostAsync("UserRestaurants", byteContent).Result;

            return(await response.Content.ReadAsStringAsync());
        }
Beispiel #10
0
        public async Task <string> NewMailSubs(int idUser, int idRestaurant)
        {
            UserRestaurant userRestaurant = await _context.UserRestaurant
                                            .Where(u => u.Idrestaurant == idRestaurant)
                                            .FirstOrDefaultAsync();


            if (userRestaurant == null)
            {
                userRestaurant.Iduser           = idUser;
                userRestaurant.Idrestaurant     = idRestaurant;
                userRestaurant.MailSubscription = true;
                _context.UserRestaurant.Add(userRestaurant);
                await _context.SaveChangesAsync();
            }
            else
            {
                userRestaurant.MailSubscription = true;
                _context.UserRestaurant.Update(userRestaurant);
                await _context.SaveChangesAsync();
            }
            return("Te has suscrito al boletín de promociones.");
        }
Beispiel #11
0
        public HttpResponseMessage Register(HttpRequestMessage request, UserRestaurantViewModel user)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false });
                }
                else
                {
                    if (!string.IsNullOrEmpty(user.UserDetails.Username))
                    {
                        var existingUserDb = _userRepository.GetSingleByUsername(user.UserDetails.Username);
                        if (existingUserDb != null)// && existingUserDb.RestaurantId == restaurantdetail.ID)
                        {
                            ModelState.AddModelError("Invalid User", "User name already exists");
                            response = request.CreateResponse(HttpStatusCode.BadRequest,
                                                              ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                                                              .Select(m => m.ErrorMessage).ToArray());
                        }
                        else
                        {
                            Entities.User _user = _membershipService.CreateUser(user.UserDetails.Username, user.UserDetails.Username, user.UserDetails.Password, new int[] { 1 });
                            UserRestaurant newuserestaurant = new UserRestaurant();
                            newuserestaurant.RestaurantId = user.ID;
                            newuserestaurant.UserId = _user.ID;
                            _userrestaurant.Add(newuserestaurant);
                            _unitOfWork.Commit();
                            response = request.CreateResponse(HttpStatusCode.OK, new { success = true });
                        }
                    }
                }
                return response;
            }));
        }
Beispiel #12
0
        public IActionResult Add(UserRestaurant userRestaurant)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            else
            {
                //UserRestaurant.addRestaurant(userRestaurant);
                //List<string> userRestaurantList = new List<string>();
                //foreach (UserRestaurant r in UserRestaurant.userList)
                //{
                //if there is no favorite dish return everything is tasty
                //  string dish = (r.FavDish == "" ^ r.FavDish is null) ? "It's all tasty" : r.FavDish;

                //                   userRestaurantList.Add($"{r.UserName}, {r.Name}, Favorite Dish: {dish}, {r.Phone}");

                //               }

                RestaurantList.AddRestaurant(userRestaurant);

                return(View("UserPage", RestaurantList.UserRestaurants));
            }
        }
Beispiel #13
0
        public HttpResponseMessage Register(HttpRequestMessage request, RestaurantUserAddressViewModel restaurantuseraddressvm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                UserViewModel uservm = new UserViewModel();

                if (!ModelState.IsValid)
                {
                    // response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false });
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    if (restaurantuseraddressvm.RestaurantUserVM != null)
                    {
                        var existingUser = _userRepository.GetSingleByUsername(restaurantuseraddressvm.RestaurantUserVM.Username);

                        if (existingUser != null)
                        {
                            //throw new Exception("Username is already in use");
                            // ModelState.AddModelError("Invalid user", "Email or User number already exists");
                            //response = request.CreateResponse(HttpStatusCode.BadRequest,
                            //ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                            //      .Select(m => m.ErrorMessage).ToArray());
                            response = request.CreateErrorResponse(HttpStatusCode.Ambiguous, "Email or User number already exists");
                        }
                        else
                        {
                            //Add Address details
                            Address newaddress = new Address();
                            Restaurant newRestaurant = new Restaurant();
                            RestaurantAddress newrestaurantAddress = new RestaurantAddress();
                            UserRestaurant newuserestaurant = new UserRestaurant();
                            //Note : -
                            //Username   --> Email
                            Entities.User _user = _membershipService.CreateUser(restaurantuseraddressvm.RestaurantUserVM.Username, restaurantuseraddressvm.RestaurantUserVM.Username, restaurantuseraddressvm.RestaurantUserVM.Password, new int[] { 1 });

                            newRestaurant.UpdateRestaurant(restaurantuseraddressvm, _user.ID);
                            _restaurant.Add(newRestaurant);
                            _unitOfWork.Commit();

                            newuserestaurant.RestaurantId = newRestaurant.ID;
                            newuserestaurant.UserId = _user.ID;

                            _userrestaurant.Add(newuserestaurant);
                            _unitOfWork.Commit();


                            //// Update view model
                            //customer = Mapper.Map<Customer, CustomerViewModel>(newCustomer);
                            //response = request.CreateResponse<CustomerViewModel>(HttpStatusCode.Created, customer);

                            foreach (var restaurantAddress in restaurantuseraddressvm.RestaurantAddressVM)
                            {
                                newaddress.UpdateAddress(restaurantAddress, restaurantuseraddressvm.RestaurantUserVM.Username, _user.ID);
                                _address.Add(newaddress);
                                _unitOfWork.Commit();

                                newrestaurantAddress.RestaurantId = newRestaurant.ID;
                                newrestaurantAddress.AddressId = newaddress.ID;

                                _restaurantaddress.Add(newrestaurantAddress);
                                _unitOfWork.Commit();

                                //int i = restaurantuseraddressvm.PlanID;
                                foreach (var resturantsubscription in restaurantuseraddressvm.SubcriptionVM)
                                {
                                    Subscription newsubscription = new Subscription();
                                    newsubscription.SubscriptionPlanId = resturantsubscription.ID;
                                    newsubscription.StartDate = DateTime.UtcNow;
                                    newsubscription.TrialStartDate = DateTime.UtcNow;
                                    newsubscription.EndDate = GetPlanIntervalEnddate(resturantsubscription.IntervalId);
                                    newsubscription.EndDate = GetPlanIntervalEnddate(resturantsubscription.IntervalId);
                                    newsubscription.RestaurantId = newRestaurant.ID;
                                    newsubscription.TransId = "";
                                    newsubscription.Status = true;
                                    _subscriptionRepository.Add(newsubscription);
                                    _unitOfWork.Commit();
                                }
                            }



                            if (_user != null)
                            {
                                uservm = Mapper.Map <User, UserViewModel>(_user);
                                response = request.CreateResponse <UserViewModel>(HttpStatusCode.OK, uservm);



                                // response = request.CreateResponse(HttpStatusCode.OK, new { success = true });
                            }
                            else
                            {
                                response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "Registration failed. Try again.");
                            }
                        }
                    }


                    //restaurantuseraddressvm.RestaurantUserVM.Add(uservm);
                    // response = request.CreateResponse<RestaurantUserAddressViewModel>(HttpStatusCode.OK, restaurantuseraddressvm);



                    // response = request.CreateResponse(HttpStatusCode.OK, new { success = true });
                }

                return response;
            }));
        }