Exemplo n.º 1
0
        public virtual Order Execute(Ordered ordered)
        {
            _validator.ValidateAndThrow(ordered);

            RestaurantDetail restaurantDetail = _restaurantGateway.findById(ordered.RestaurantUuid);
            List <MenuItem>  items            = restaurantDetail.Items;

            bool orderOk = ordered.Items.TrueForAll(orderedItem =>
                                                    items.Exists(menuItem =>
                                                                 menuItem.Uuid.Equals(orderedItem.Uuid) && menuItem.Value == orderedItem.UnitValue
                                                                 )
                                                    );

            if (orderOk)
            {
                var restaurant = new Restaurant(restaurantDetail.Uuid, restaurantDetail.Name);
                List <OrderItem> orderItems = ordered.Items.Select(orderedItem =>
                {
                    MenuItem menuItem = items.Find(menuItem => menuItem.Uuid.Equals(orderedItem.Uuid));
                    return(new OrderItem(menuItem.Uuid, menuItem.Name, orderedItem.Amount, menuItem.Value));
                }).ToList();
                var order = new Order(Guid.NewGuid().ToString(), restaurant, orderItems, ordered.Total);
                return(_orderGateway.register(order));
            }

            throw new InvalidOrderException(
                      "0002",
                      "invalidOrderException",
                      "Order with invalid items");
        }
        public async Task <IActionResult> GetRestaurantById(int id)
        {
            var restaurant = await _db.Restaurants.FindAsync(id);

            if (restaurant == null)
            {
                return(NotFound());
            }

            double totalScore = 0;

            foreach (Rating rating in restaurant.Ratings)
            {
                totalScore += rating.Score;
            }

            var restaurantDetail = new RestaurantDetail()
            {
                Id           = restaurant.Id,
                Name         = restaurant.Name,
                Location     = restaurant.Location,
                AverageScore = totalScore / restaurant.Ratings.Count
            };

            return(Ok(restaurantDetail));
        }
        public IActionResult RestaurannEdit(RestaurantDetail restaurantDetailEdit)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(restaurantDetailEdit).State = EntityState.Modified;
                _db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }

            return(View(restaurantDetailEdit));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Reservation(RestaurantDetail model)
        {
            string            firstName   = HttpContext.Request.Form["firstName"];
            string            lastName    = HttpContext.Request.Form["lastName"];
            string            email       = HttpContext.Request.Form["email"];
            string            Phone       = HttpContext.Request.Form["Phone"];
            string            noGuests    = HttpContext.Request.Form["noGuests"];
            string            datepicker  = HttpContext.Request.Form["datepicker"];
            string            ddTime      = HttpContext.Request.Form["ddTime"];
            string            resType     = HttpContext.Request.Form["resType"];
            ReservationDetail _resvDetail = new ReservationDetail();

            _resvDetail.createdDate      = DateTime.Now;
            _resvDetail.firstName        = firstName;
            _resvDetail.lastName         = lastName;
            _resvDetail.guestNum         = Convert.ToInt32(noGuests);
            _resvDetail.reservationDate  = datepicker;
            _resvDetail.reservationEmail = email;
            _resvDetail.reservationPhone = Phone;
            _resvDetail.reservationTime  = ddTime;
            _resvDetail.reservationType  = resType;
            _resvDetail.restaurantId     = model.id;
            _context.ReservationDetail.Add(_resvDetail);
            _context.SaveChanges();

            //to admin
            string msg = string.Empty;

            msg += "A new Reservation has been made at  " + @model.restaurantName + " by " + firstName + " " + lastName + "<br/>";
            msg += "<b> Total Number of Guests : </b>" + noGuests + "<br/> <b> " + firstName + "'s Phone Number </b>" + Phone + " and <b> email address :</b>" + email;
            msg += "<br/> Reservation is made for Day : " + datepicker + " at " + ddTime + " for " + resType;

            await _emailSender.SendEmailAsync(email, "New Reservation request", msg);

            ////to user
            //string msg1 = string.Empty;
            //msg1 += "Hello " + firstName + " " + lastName + ",<br/>";
            //msg1 += "Your request for resrvation at " + model.restaurantName + " for " + resType + " on " + datepicker + " at " + ddTime + " Has been recieved. Our staff will wait for you thanks.<br/>";

            //await _emailSender.SendEmailAsync(email, "Reservation at Arfler", msg1);

            return(View());
        }
        public async Task <IHttpActionResult> GetRestaurantById(int id)
        {
            Restaurant restaurant = await _context.Restaurants.FindAsync(id);

            if (restaurant == default)
            {
                return(NotFound()); // 404
            }


            RestaurantDetail restaurantDetail = new RestaurantDetail()
            {
                Id               = restaurant.Id,
                Name             = restaurant.Name,
                Address          = restaurant.Address,
                Owner            = restaurant.Owner,
                Rating           = restaurant.Rating,
                AverageFoodScore = restaurant.AverageFoodScore
            };

            return(Ok(restaurantDetail)); //200
        }
Exemplo n.º 6
0
        // GET: Restaurants/Details/5
        public async Task <ActionResult <RestaurantDetail> > Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RestaurantDetail res = new RestaurantDetail();

            var restaurant = await _context.Restaurants
                             .Include(r => r.CreatedBy)
                             .FirstOrDefaultAsync(m => m.Id == id);

            if (restaurant == null)
            {
                return(NotFound());
            }

            res.Restaurant = restaurant;
            res.Reviews    = await _context.Reviews.Where(x => x.RestaurantId == restaurant.Id).ToListAsync();

            return(View(res));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> QuickAdd(RestaurantDetail model, long?Id)
        {
            string zipCode = HttpContext.Request.Form["ZipCode"];

            if (Id == null)
            {
                //var user = await GetCurrentUserAsync();
                //  model.userId = user.id;
                model.zipCode      = zipCode;
                model.createdDate  = DateTime.Now;
                model.modifiedDate = DateTime.Now;
                _context.RestaurantDetail.Add(model);
                _context.SaveChanges();
                var restId = _context.RestaurantDetail.Max(a => a.id);
                MenuCategoryDetail objmenucats = new MenuCategoryDetail();
                objmenucats.createdDate          = DateTime.Now;
                objmenucats.isEnabled            = true;
                objmenucats.parentMenuCategoryId = null;
                objmenucats.menuCategoryDesc     = null;
                objmenucats.menuCategoryName     = "Breakfast";
                objmenucats.modifiedDate         = DateTime.Now;
                objmenucats.restaurantId         = restId;
                objmenucats.sortOrder            = 1;
                _context.MenuCategoryDetail.Add(objmenucats);
                _context.SaveChanges();

                MenuCategoryDetail objmenucats1 = new MenuCategoryDetail();
                objmenucats1.createdDate         = DateTime.Now;
                objmenucats1.isEnabled           = true;
                objmenucats.parentMenuCategoryId = null;
                objmenucats1.menuCategoryDesc    = null;
                objmenucats1.menuCategoryName    = "Lunch";
                objmenucats1.modifiedDate        = DateTime.Now;
                objmenucats1.restaurantId        = restId;
                objmenucats1.sortOrder           = 2;
                _context.MenuCategoryDetail.Add(objmenucats1);
                _context.SaveChanges();

                MenuCategoryDetail objmenucats2 = new MenuCategoryDetail();
                objmenucats2.createdDate         = DateTime.Now;
                objmenucats2.isEnabled           = true;
                objmenucats2.menuCategoryDesc    = null;
                objmenucats.parentMenuCategoryId = null;
                objmenucats2.menuCategoryName    = "Dinner";
                objmenucats2.modifiedDate        = DateTime.Now;
                objmenucats2.restaurantId        = restId;
                objmenucats2.sortOrder           = 3;
                _context.MenuCategoryDetail.Add(objmenucats2);
                _context.SaveChanges();
                return(RedirectToAction("AddCategories", "Home", new { id = restId }));
            }
            else
            {
                RestaurantDetail objrest      = new RestaurantDetail();
                string           add2         = HttpContext.Request.Form["Address2"];
                string           tagline      = HttpContext.Request.Form["tagline"];
                string           userId       = HttpContext.Request.Form["userId"];
                string           Desc         = HttpContext.Request.Form["Desc"];
                string           country      = HttpContext.Request.Form["country"];
                string           rimage       = HttpContext.Request.Form["rimage"];
                string           Rcategoryids = HttpContext.Request.Form["Rcategoryids"];
                string           isenable     = HttpContext.Request.Form["isenable"];
                string           sortOrder    = HttpContext.Request.Form["sortOrder"];

                objrest.address1 = model.address1;
                if (!string.IsNullOrEmpty(add2))
                {
                    objrest.address2 = add2;
                }
                else
                {
                    objrest.address2 = null;
                }

                if (!string.IsNullOrEmpty(tagline))
                {
                    objrest.tagline = tagline;
                }
                else
                {
                    objrest.tagline = null;
                }

                if (!string.IsNullOrEmpty(userId))
                {
                    objrest.userId = userId;
                }
                else
                {
                    objrest.userId = null;
                }

                if (!string.IsNullOrEmpty(Desc))
                {
                    objrest.Description = Desc;
                }
                else
                {
                    objrest.Description = null;
                }

                if (!string.IsNullOrEmpty(country))
                {
                    objrest.country = country;
                }
                else
                {
                    objrest.country = null;
                }

                if (!string.IsNullOrEmpty(rimage))
                {
                    objrest.mainImageUrl = rimage;
                }
                else
                {
                    objrest.mainImageUrl = null;
                }

                if (!string.IsNullOrEmpty(Rcategoryids))
                {
                    objrest.categoryIds = Rcategoryids;
                }
                else
                {
                    objrest.categoryIds = null;
                }


                objrest.isEnable = true;


                if (!string.IsNullOrEmpty(sortOrder))
                {
                    objrest.sortOrder = Convert.ToInt32(sortOrder);
                }



                objrest.zipCode        = zipCode;
                objrest.city           = model.city;
                objrest.state          = model.state;
                objrest.intro          = model.intro;
                objrest.restaurantName = model.restaurantName;
                objrest.createdDate    = DateTime.Now;
                objrest.modifiedDate   = DateTime.Now;
                objrest.id             = Convert.ToInt32(Id);
                _context.Update(objrest);
                _context.SaveChanges();

                return(RedirectToAction("AddCategories", "Home", new { id = Id }));
            }
        }
 public IActionResult RestaurantDetaillAdd(RestaurantDetail restaurantDetail)
 {
     _db.restaurantDetails.Add(restaurantDetail);
     _db.SaveChanges();
     return(RedirectToAction("Index", "Home"));
 }
Exemplo n.º 9
0
        //Post : Admin/RestaurantDetails/
        public async Task <IActionResult> RestaurantDetails(RestaurantDetail model)
        {
            string ddBrakTimeFrom = HttpContext.Request.Form["ddBrakTimeFrom"];
            string ddBrakTimeTo   = HttpContext.Request.Form["ddBreakTimingTO"];

            var user = await GetCurrentUserAsync();

            if (user != null)
            {
                var role = await _userManager.GetRolesAsync(user);

                TempData["userRole"] = role[0];
                string aa       = HttpContext.Request.Form["cats"];
                string filename = HttpContext.Request.Form["file"];

                string filepath = HttpContext.Request.Form["filePath"];

                if (!string.IsNullOrEmpty(filepath))
                {
                    CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("hkm2gz727", "654416183426452", "AZJIv_WvBo1Z7gkzN-uXFVg2_BE");
                    Cloudinary cloudinary            = new Cloudinary(account);

                    CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams();
                    uploadParams.File = new CloudinaryDotNet.Actions.FileDescription(filepath);

                    CloudinaryDotNet.Actions.ImageUploadResult uploadResult = await cloudinary.UploadAsync(uploadParams);

                    string url = cloudinary.Api.UrlImgUp.BuildUrl(String.Format("{0}.{1}", uploadResult.PublicId, uploadResult.Format));
                    model.mainImageUrl = url;
                }
                else
                {
                    string imageurl = HttpContext.Request.Form["imageurl"];
                    model.mainImageUrl = imageurl;
                }
                model.timing1 = model.timing1;
                model.timing2 = model.timing2;

                if (model.id != 0)
                {
                    model.userId       = model.userId;
                    model.categoryIds  = aa;
                    model.modifiedDate = DateTime.Now;
                    _context.RestaurantDetail.Update(model);
                    _context.SaveChanges();
                }
                else
                {
                    model.userId       = user.Id;
                    model.categoryIds  = aa;
                    model.createdDate  = DateTime.Now;
                    model.modifiedDate = DateTime.Now;
                    model.sortOrder    = _context.RestaurantDetail.Max(a => a.sortOrder) + 1;
                    _context.RestaurantDetail.Add(model);
                    _context.SaveChanges();
                }
                var restId = _context.RestaurantDetail.Max(a => a.id);
                MenuCategoryDetail objmenucats = new MenuCategoryDetail();
                objmenucats.createdDate          = DateTime.Now;
                objmenucats.isEnabled            = true;
                objmenucats.parentMenuCategoryId = null;
                objmenucats.menuCategoryDesc     = null;
                objmenucats.menuCategoryName     = "Breakfast";
                objmenucats.modifiedDate         = DateTime.Now;
                objmenucats.restaurantId         = restId;
                objmenucats.sortOrder            = 1;
                _context.MenuCategoryDetail.Add(objmenucats);
                _context.SaveChanges();

                MenuCategoryDetail objmenucats1 = new MenuCategoryDetail();
                objmenucats1.createdDate         = DateTime.Now;
                objmenucats1.isEnabled           = true;
                objmenucats.parentMenuCategoryId = null;
                objmenucats1.menuCategoryDesc    = null;
                objmenucats1.menuCategoryName    = "Lunch";
                objmenucats1.modifiedDate        = DateTime.Now;
                objmenucats1.restaurantId        = restId;
                objmenucats1.sortOrder           = 2;
                _context.MenuCategoryDetail.Add(objmenucats1);
                _context.SaveChanges();

                MenuCategoryDetail objmenucats2 = new MenuCategoryDetail();
                objmenucats2.createdDate         = DateTime.Now;
                objmenucats2.isEnabled           = true;
                objmenucats2.menuCategoryDesc    = null;
                objmenucats.parentMenuCategoryId = null;
                objmenucats2.menuCategoryName    = "Dinner";
                objmenucats2.modifiedDate        = DateTime.Now;
                objmenucats2.restaurantId        = restId;
                objmenucats2.sortOrder           = 3;
                _context.MenuCategoryDetail.Add(objmenucats2);
                _context.SaveChanges();
                return(RedirectToAction("Index", "Admin"));
            }
            else
            {
                return(RedirectToAction("QuickRegister", "Account"));
            }
        }