Esempio n. 1
0
        public HttpResponseMessage Update(HttpRequestMessage request, RestaurantUserAddressViewModel restaurantuseraddressvm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    Restaurant newRestaurant = new Restaurant();
                    Address newaddress = new Address();
                    newRestaurant.UpdateRestaurantEdit(restaurantuseraddressvm, restaurantuseraddressvm.RestaurantUserVM.ID);
                    _restaurantRepository.Edit(newRestaurant);
                    _unitOfWork.Commit();
                    foreach (var restaurantAddress in restaurantuseraddressvm.RestaurantAddressVM)
                    {
                        newaddress.UpdateAddressEdit(restaurantAddress, restaurantuseraddressvm.RestaurantUserVM.Email, restaurantuseraddressvm.RestaurantUserVM.ID);
                        _addressRepository.Edit(newaddress);
                        _unitOfWork.Commit();
                    }
                    response = request.CreateResponse(HttpStatusCode.OK, new { success = true });
                }

                return response;
            }));
        }
Esempio n. 2
0
        //public static void UpdateRestaurant(this Restaurant restaurant, RestaurantUserViewModel restaurantVm)
        //{
        //    restaurant.Name = restaurantVm.Name;
        //    restaurant.Description = restaurantVm.Description;
        //    restaurant.GlobalBar = false;
        //    restaurant.AutoOrder = false;
        //    restaurant.NoQty =false;
        //    restaurant.Status=true;
        //    restaurant.CreatedBy=restaurantVm.UserEmail;
        //    restaurant.CreatedDate = DateTime.Now;



        //}

        public static void UpdateRestaurant(this Restaurant restaurant, RestaurantUserAddressViewModel restaurantVm, int userId)
        {
            restaurant.Name        = restaurantVm.Name;
            restaurant.Description = restaurantVm.Description;
            restaurant.GlobalBar   = false;
            restaurant.AutoOrder   = false;
            restaurant.NoQty       = false;
            restaurant.Status      = true;
            restaurant.CreatedBy   = Convert.ToString(userId);
            restaurant.CreatedDate = DateTime.Now;
        }
Esempio n. 3
0
        public HttpResponseMessage Get(HttpRequestMessage request, string filter = null)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                RestaurantUserAddressViewModel restusrvm = new RestaurantUserAddressViewModel();
                if (!string.IsNullOrEmpty(filter))
                {
                    var existingUserDb = _userRepository.GetSingleByUsername(filter);

                    if (existingUserDb != null)
                    {
                        var userrestaurantDb = _userrestaurantRepository.GetAll().Where(userrest => userrest.UserId == existingUserDb.ID).ToList();
                        foreach (var userrestaurant in userrestaurantDb)
                        {
                            // var restaurantDb = _restaurantRepository.AllIncluding().Where(r => r.UserRestaurants.Any(ur => ur.User.ID == existingUserDb.ID)).AsQueryable();
                            var restaurantDb = _restaurantRepository.GetSingle(userrestaurant.RestaurantId);

                            restusrvm.ID = restaurantDb.ID;
                            restusrvm.Name = restaurantDb.Name.ToString();
                            restusrvm.Description = restaurantDb.Description.ToString();
                            restusrvm.AutoOrder = restaurantDb.AutoOrder;
                            restusrvm.GlobalBar = restaurantDb.GlobalBar;
                            restusrvm.RestaurantAddressVM = GetRestuarantDetail(restusrvm.ID);
                            restusrvm.RestaurantUserVM = GetUserDetail(userrestaurant.UserId);
                        }

                        response = request.CreateResponse <RestaurantUserAddressViewModel>(HttpStatusCode.OK, restusrvm);
                        return response;
                    }
                    else
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Invalid User");
                    }
                }

                else
                {
                    response = request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Invalid User");
                }



                return response;
            }));
        }
Esempio n. 4
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;
            }));
        }