Beispiel #1
0
        public ActionResult SignUp(User userVM)
        {
            try
            {
                CustomJsonResult result = new CustomJsonResult();
                var pass = Cryptography.GetMD5Hash(userVM.Password);
                // Check if the email already exists.
                User us = db.Users.Where(u => u.Email == userVM.Email && u.Password == pass).FirstOrDefault();
                if (us == null)
                {
                    db.Users.Add(userVM);
                    db.SaveChanges();

                    result.Data = new { Result = true, User = userVM };
                }
                else
                {
                    result.Data = new { Result = false };
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public static UserVM UpdateUserDetails(UserVM userVM)
        {
            try
            {
                User user = db.Users.Find(userVM.Id);
                user.FirstName   = userVM.FirstName;
                user.LastName    = userVM.LastName;
                user.Address     = userVM.Address;
                user.Birthday    = userVM.Birthday;
                user.City        = userVM.City;
                user.Country     = userVM.Country;
                user.Email       = userVM.Email;
                user.Username    = userVM.Username;
                user.PhoneNumber = userVM.PhoneNumber;
                user.Gender      = userVM.Gender;
                if (!string.IsNullOrEmpty(userVM.Password))
                {
                    user.Password = userVM.Password;
                }

                db.SaveChanges();
                userVM.Password = "";
                return(userVM);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #3
0
        public ActionResult ActivateDeactivateRestaurant(string restaurantId, bool isActive)
        {
            try
            {
                CustomJsonResult result = new CustomJsonResult();

                Restaurant restaurant = db.Restaurants.Find(int.Parse(restaurantId));
                restaurant.IsActive = isActive;

                db.SaveChanges();

                var restaurants = db.Restaurants.ToList();
                var users       = db.Users.ToList();

                result.Data = new
                {
                    Result      = true,
                    Restaurants = restaurants,
                    Users       = users
                };

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #4
0
        public ActionResult Signup(Restaurant restaurant)
        {
            try
            {
                CustomJsonResult result = new CustomJsonResult();

                Restaurant res = db.Restaurants.Where(r => r.RestaurantName == restaurant.RestaurantName && r.PhoneNumber == restaurant.PhoneNumber && r.RestaurantManager.Email == restaurant.RestaurantManager.Email).FirstOrDefault();
                if (res == null)
                {
                    restaurant.RestaurantManager.Password = Cryptography.GetMD5Hash(restaurant.RestaurantManager.Password);
                    // Add new restaurant and save changes to db
                    db.Restaurants.Add(restaurant);
                    db.SaveChanges();
                    result.Data = new { Result = true, Restaurant = restaurant };
                }
                else
                {
                    result.Data = new { Result = false };
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }