Example #1
0
        public ActionResult EditNetwork(Network net)
        {
            int idToCheck = net.Id;

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var netOld = rdb.networks.Where(s => s.Id == idToCheck).FirstOrDefault();
                    netOld.Network          = net.Name;
                    rdb.Entry(netOld).State = System.Data.Entity.EntityState.Modified;
                    rdb.SaveChanges();
                    string message = "Successfully Saved!";
                    if (Request.IsAjaxRequest())
                    {
                        return(new JsonResult {
                            Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                    else
                    {
                        return(null);
                    }
                    //RedirectToAction("RemoveRestaurant", "Admin");
                    //return View();
                    //return Content(Boolean.TrueString);
                }
                catch
                {//TODO: Log error
                    //RedirectToAction("RemoveRestaurant", "Admin");
                    //return View();
                    return(Content(Boolean.FalseString));
                }
            }
        }
Example #2
0
 //вывод страницы рейтинга
 public ViewResult Rating(int?page)
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         var networks = rdb.networks.Select(s => new Network {
             Id = s.Id, Name = s.Network
         }).ToList();
         var rating = rdb.restaurants.Select(s => new RatingModel
         {
             Date         = s.DateOfCreation,
             InteriorMark = s.InteriorMark,
             KitchenMark  = s.KitchenMark,
             ServiceMark  = s.ServiceMark,
             Name         = s.Name,
             RestaurantId = s.Id,
             DistrictId   = s.DistrictId
         }).ToList();
         var districts = rdb.districts.Select(s => new DistrictModel {
             Id = s.Id, District = s.District
         }).ToList();
         ViewBag.Networks    = networks;
         ViewBag.Districts   = districts;
         ViewBag.NetworkName = "";
         return(View("Rating", rating.ToPagedList(pageNumber: page ?? 1, pageSize: 1)));
     }
 }
Example #3
0
        public ActionResult EditDistrict(District ds)
        {
            int id = ds.Id;

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var district = rdb.districts.Where(s => s.Id == id).FirstOrDefault();
                    district.District         = ds.Name;
                    rdb.Entry(district).State = System.Data.Entity.EntityState.Modified;
                    rdb.SaveChanges();
                    string message = "Successfully Saved!";
                    if (Request.IsAjaxRequest())
                    {
                        return(new JsonResult {
                            Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        });
                    }
                    else
                    {
                        return(null);
                    }
                    //return Content(Boolean.TrueString);
                }
                catch
                {//TODO: Log error
                    return(Json(false));
                    //return Content(Boolean.FalseString);
                }
            }
        }
Example #4
0
        //вывод рецензии
        public ViewResult Review(string num)
        {
            int addressId = Int32.Parse(num);

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                var review = rdb.restaurants.Where(s => s.Id == addressId).Select(n => new ReviewModel
                {
                    Id           = addressId,
                    Name         = n.Name,
                    KitchenMark  = n.KitchenMark,
                    InteriorMark = n.InteriorMark,
                    ServiceMark  = n.ServiceMark,
                    Text         = n.ReviewText,
                    Label        = n.CustomLabel,
                    Address      = n.Address,
                    Date         = n.DateOfCreation,
                    Lat          = n.Lattitude,
                    Lng          = n.Longitude,
                    KitchenType  = n.KitchenType,
                    WorkHours    = n.WorkTime,
                    Amount       = n.SumAmount,
                    Children     = n.Children,
                    Propositions = n.Propositions,
                    Music        = n.Music,
                    Phone        = n.Phones
                }).ToList()[0];
                return(View(review));
            }
        }
Example #5
0
        public ActionResult CreateDistrict(District ds)
        {
            string message = "";

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    rdb.districts.Add(new districts {
                        District = ds.Name, CityId = ds.CityId
                    });
                    rdb.SaveChanges();
                    var id = rdb.districts.Where(s => s.District.Equals(ds.Name)).Select(s => s.Id);
                    message = "Successfully Saved!" + id.ToString();
                }
                catch
                {
                    message = "Error! Please try again!";
                }
                if (Request.IsAjaxRequest())
                {
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                else
                {
                    return(PartialView());
                }
            }
        }
Example #6
0
        public ActionResult CreateNetwork(Network net)
        {
            string message = "";

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    rdb.networks.Add(new networks {
                        Network = net.Name
                    });
                    rdb.SaveChanges();
                    var id = rdb.networks.Where(s => s.Network.Equals(net.Name)).Select(s => s.Id).ToList()[0];
                    message = "Successfully Saved!" + id.ToString();
                }
                catch
                {
                    message = "Error! Please try again!";
                }
                if (Request.IsAjaxRequest())
                {
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                else
                {
                    return(PartialView());
                }
            }
        }
Example #7
0
        public ActionResult RemoveNetwork(string id)
        {
            int    idToCheck = Int32.Parse(id);
            string message;

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var network = rdb.networks.Where(s => s.Id == idToCheck).FirstOrDefault();
                    rdb.networks.Remove(network);
                    rdb.SaveChanges();
                    message = "Successfully removed!";
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                    //return View("AdminMenu");
                    //return RedirectToAction("RemoveRestaurant");
                    //return View();
                    //return Content(Boolean.TrueString);
                }
                catch
                {//TODO: Log error
                    message = "Error";
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                    //return View("AdminMenu");
                    //return RedirectToAction("RemoveRestaurant");
                    //return View();
                    //return Content(Boolean.FalseString);
                }
            }
        }
Example #8
0
 public ActionResult EditComments(int?page)
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         var comments = rdb.usercomments.Select(s => new CustomLabelModel {
             Date = s.DateOfCreation, LabelText = s.Comment, Name = s.UserName, Id = s.Id
         }).ToList();
         return(View("EditComments", comments.ToPagedList(pageNumber: page ?? 1, pageSize: 1)));
     }
 }
Example #9
0
 public ActionResult EditComment(string id)
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         int idOfEditedComment = Int32.Parse(id);
         var comment           = rdb.usercomments.Where(s => s.Id == idOfEditedComment).Select(x => new CustomLabelModel {
             Date = x.DateOfCreation, Id = x.Id, LabelText = x.Comment, E_mail = x.Email
         }).ToList()[0];
         return(View(comment));
     }
 }
Example #10
0
 public ActionResult SearchReview()
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         var restaurants = rdb.restaurants.Select(s => new Restaurant {
             Name = s.Name, Address = s.Address, Id = s.Id
         }).ToList();
         ViewBag.Restaurants = restaurants;
         return(View());
     }
 }
Example #11
0
        public ActionResult SaveUploadedFile()
        {
            //id of newly created review
            string folderName = "";

            //here we will get the last id of restaurant
            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                int id = rdb.restaurants.OrderByDescending(s => s.Id).FirstOrDefault().Id;
                folderName = id.ToString();
            }


            //here we will save images
            bool   isSavedSuccessfully = true;
            string fName = "";

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];
                //Save file content goes here
                fName = file.FileName;
                if (file != null && file.ContentLength > 0)
                {
                    var originalDirectory = new DirectoryInfo(string.Format("{0}images\\Restaurants\\" + "rest_" + folderName, Server.MapPath(@"\")));

                    string pathString = originalDirectory.ToString();

                    var fileName1 = Path.GetFileName(file.FileName);


                    bool isExists = System.IO.Directory.Exists(pathString);

                    if (!isExists)
                    {
                        System.IO.Directory.CreateDirectory(pathString);
                    }

                    var path = string.Format("{0}\\{1}", pathString, file.FileName);
                    file.SaveAs(path);
                }
            }

            if (isSavedSuccessfully)
            {
                return(Json(new { Message = "Новая рецензия занесена в базу" }));
            }
            else
            {
                return(Json(new { Message = "Не получается сохранить фотографии" }));
            }
        }
Example #12
0
 public PartialViewResult LabelView(int num)
 {
     //creates partial label view
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         var labels = rdb.usercomments.Where(s => s.RestaurantId == num).Select(n => new CustomLabelModel {
             Date   = n.DateOfCreation,
             E_mail = n.Email, LabelText = n.Comment, Name = n.UserName
         }).ToList();
         ViewBag.Users = labels;
         ViewBag.ID    = num;
         return(PartialView());
     }
 }
Example #13
0
 public ActionResult AdminPlaces()
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         var cities = rdb.cities.Select(s => new City {
             Id = s.Id, Name = s.City
         }).ToList();
         var districts = rdb.districts.Select(s => new District {
             CityId = s.CityId, Id = s.Id, Name = s.District
         }).ToList();
         ViewBag.Cities    = cities;
         ViewBag.Districts = districts;
         return(View());
     }
 }
Example #14
0
 public ActionResult RemoveRestaurant()
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         var networks = rdb.networks.Select(s => new Network {
             Id = s.Id, Name = s.Network
         }).ToList();
         ViewBag.Networks = networks;
         var restaurants = rdb.restaurants.Select(s => new Restaurant {
             Name = s.Name, Address = s.Address, Id = s.Id, NetworkId = s.NetworkId
         }).ToList();
         ViewBag.Restaurants = restaurants;
         return(View());
     }
 }
Example #15
0
        public ActionResult EditReview(string id)
        {
            int idR = Int32.Parse(id);

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                var rest = rdb.restaurants.Where(s => s.Id == idR).Select(s => new AdminSaveModel
                {
                    Address        = s.Address,
                    Amount         = s.SumAmount,
                    Children       = s.Children,
                    DistrictId     = s.DistrictId,
                    Id             = idR,
                    InteriorMark   = s.InteriorMark,
                    KitchenMark    = s.KitchenMark,
                    KitchenType    = s.KitchenType,
                    Lat            = s.Lattitude.ToString(),
                    Lng            = s.Longitude.ToString(),
                    RestaurantName = s.Name,
                    Music          = s.Music,
                    NetworkId      = s.NetworkId,
                    Propositions   = s.Propositions,
                    ReviewText     = s.ReviewText,
                    Phones         = s.Phones,
                    ServiceMark    = s.ServiceMark,
                    WorkHours      = s.WorkTime,
                    CityId         = s.districts.CityId
                }).ToList()[0];
                var districts = rdb.districts.Select(s => new District {
                    Id = s.Id, CityId = s.CityId, Name = s.District
                }).ToList();

                //networks
                var networks = rdb.networks.Select(s => new Network {
                    Id = s.Id, Name = s.Network
                }).ToList();

                //get cities
                var cities = rdb.cities.Select(s => new City {
                    Id = s.Id, Name = s.City
                }).ToList();

                ViewBag.Districts = districts;
                ViewBag.Networks  = networks;
                ViewBag.Cities    = cities;
                return(View(rest));
            }
        }
Example #16
0
        public void RemoveComment(string id)
        {
            int idToCheck = Int32.Parse(id);

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var comment = rdb.usercomments.Where(s => s.Id == idToCheck).FirstOrDefault();
                    rdb.usercomments.Remove(comment);
                    rdb.SaveChanges();
                }
                catch
                {//TODO: Log error
                }
            }
        }
Example #17
0
        public void UpdateComment(CustomLabelModel clm)
        {
            int id = clm.Id;

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var comment = rdb.usercomments.Where(s => s.Id == id).FirstOrDefault();
                    comment.Comment          = clm.LabelText;
                    rdb.Entry(comment).State = System.Data.Entity.EntityState.Modified;
                    rdb.SaveChanges();
                }
                catch
                {//TODO: Log error
                }
            }
        }
Example #18
0
        public ViewResult Search(string word, int?page)
        {
            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                //search the network
                var tempNetwork = rdb.networks.Where(s => s.Network.ToLower().Contains(word.ToLower())).Select(s => s.Id);
                if (tempNetwork.ToList().Count != 0)
                {
                    int networkId       = tempNetwork.ToList()[0];
                    var netSearchResult = rdb.restaurants.Where(s => s.NetworkId == networkId).Select(s => new SearchModel {
                        Id = s.Id, Name = s.Name
                    }).ToList();
                }
                //the search by name
                var rating1 = rdb.restaurants.Where(s => s.Name.Contains(word.Substring(0))).Select(s => new SearchModel {
                    Id = s.Id, Name = s.Name
                }).ToList();
                //here the search will be by kitchen type, for example "chinese food", and then we do intersection of lists
                var rating2 = rdb.restaurants.Where(s => s.KitchenType.Contains(word.Substring(0))).Select(s => new SearchModel {
                    Id = s.Id, Name = s.Name
                }).ToList();
                //the search will by by propositions, for example "vegetarian food"
                var rating3 = rdb.restaurants.Where(s => s.Propositions.Contains(word.Substring(0))).Select(s => new SearchModel {
                    Id = s.Id, Name = s.Name
                }).ToList();
                var rating4 = rdb.restaurants.Where(s => s.ReviewText.Contains(word.Substring(0))).Select(s => new SearchModel {
                    Id = s.Id, Name = s.Name
                }).ToList();

                var hs12 = new HashSet <SearchModel>(rating1, new SearchModelComparer());
                hs12.UnionWith(rating2);
                var rating12 = hs12.ToList();

                var hs123 = new HashSet <SearchModel>(rating12, new SearchModelComparer());
                hs123.UnionWith(rating3);
                var rating123 = hs123.ToList();

                var hs1234 = new HashSet <SearchModel>(rating123, new SearchModelComparer());
                hs1234.UnionWith(rating4);
                var rating1234 = hs1234.ToList();

                return(View("Search", rating1234.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
            }
        }
Example #19
0
 public ActionResult Index()
 {
     using (restaurants_dbEntities rdb = new restaurants_dbEntities())
     {
         //выбираем из базы необходимые данные используя модель и передаем лист моделей position в view
         var position = rdb.restaurants.Select(s => new Position
         {
             Lat         = s.Lattitude,
             Lng         = s.Longitude,
             Name        = s.Name,
             AddressId   = s.Id,
             CustomLabel = s.CustomLabel,
             Review      = s.ReviewText,
             Kitchen     = s.KitchenMark,
             Service     = s.ServiceMark,
             Interior    = s.InteriorMark,
             Date        = s.DateOfCreation
         }).ToList();
         return(View(position));
     }
 }
Example #20
0
        public ActionResult RemoveDistrict(string id)
        {
            int idToCheck = Int32.Parse(id);

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var district = rdb.districts.Where(s => s.Id == idToCheck).FirstOrDefault();
                    rdb.districts.Remove(district);
                    rdb.SaveChanges();
                    return(Json(true));
                    //return Content(Boolean.TrueString);
                }
                catch
                {//TODO: Log error
                    return(Json(false));
                    //return Content(Boolean.FalseString);
                }
            }
        }
Example #21
0
        public ActionResult RemoveReview(string id)
        {
            int    idToCheck  = Int32.Parse(id);
            string folderName = id;
            string message;

            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                try
                {
                    var rest = rdb.restaurants.Where(s => s.Id == idToCheck).FirstOrDefault();
                    rdb.restaurants.Remove(rest);
                    rdb.SaveChanges();
                    //return Json(true);
                    //return Content(Boolean.TrueString);
                    message = "Successfully removed!";
                    var    originalDirectory = new DirectoryInfo(string.Format("{0}images\\Restaurants\\" + "rest_" + folderName, Server.MapPath(@"\")));
                    string pathString        = originalDirectory.ToString();
                    bool   isExists          = System.IO.Directory.Exists(pathString);
                    if (isExists)
                    {
                        Directory.Delete(pathString, true);
                    }

                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                catch
                {//TODO: Log error
                    //return Json(false);
                    //return Content(Boolean.FalseString);
                    message = "Error!";
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
        }
Example #22
0
        public ActionResult SaveLabel(CustomLabelModel lb)
        {
            string message = "";

            if (ModelState.IsValid)
            {
                try
                {
                    using (restaurants_dbEntities rdb = new restaurants_dbEntities())
                    {
                        rdb.usercomments.Add(new usercomments {
                            Comment = lb.LabelText, DateOfCreation = DateTime.Now, RestaurantId = lb.ReviewID, UserName = lb.Name, Email = lb.E_mail
                        });
                        rdb.SaveChanges();
                        message = "Successfully Saved!";
                    }
                }
                catch (Exception ex)
                {
                    message = "Error. Please try egain!";
                }
            }
            else
            {
                message = "Please provide required fields value.";
            }
            if (Request.IsAjaxRequest())
            {
                return(new JsonResult {
                    Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            else
            {
                ViewBag.Message = message;
                return(View());
            }
        }
Example #23
0
        public ActionResult CreateReview()
        {
            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                //get districts
                var districts = rdb.districts.Select(s => new District {
                    Id = s.Id, CityId = s.CityId, Name = s.District
                }).ToList();

                //networks
                var networks = rdb.networks.Select(s => new Network {
                    Id = s.Id, Name = s.Network
                }).ToList();

                //get cities
                var cities = rdb.cities.Select(s => new City {
                    Id = s.Id, Name = s.City
                }).ToList();
                ViewBag.Districts = districts;
                ViewBag.Networks  = networks;
                ViewBag.Cities    = cities;
            }
            return(View());
        }
Example #24
0
        public ActionResult CreateReview(AdminSaveModel rmd)
        {
            int?netId;

            if (rmd.NetworkId == null)
            {
                netId = 1;
            }
            else
            {
                netId = rmd.NetworkId;
            }

            string message;
            string hashtag = "";

            if (rmd.ReviewText != null)
            {
                if (rmd.ReviewText.Contains('#'))
                {
                    //get hashtag expression
                    var           regex   = new Regex(@"(?<=#)\w+");
                    var           matches = regex.Matches(rmd.ReviewText);
                    StringBuilder stb     = new StringBuilder();
                    foreach (Match m in matches)
                    {
                        stb.Append(m.Value);
                        stb.Append(" ");
                    }
                    if (stb[stb.Length - 1].ToString().Equals(" "))
                    {
                        stb.Remove(stb.Length - 1, 1);
                    }
                    hashtag = stb.ToString();
                }
            }
            else
            {
                rmd.ReviewText = "";
            }
            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                double ln = double.Parse(rmd.Lng.Replace('.', ','));
                double la = double.Parse(rmd.Lat.Replace('.', ','));
                rdb.restaurants.Add(new restaurants
                {
                    Address        = rmd.Address,
                    Children       = rmd.Children,
                    DateOfCreation = DateTime.Now,
                    DistrictId     = rmd.DistrictId,
                    InteriorMark   = rmd.InteriorMark,
                    KitchenMark    = rmd.KitchenMark,
                    ServiceMark    = rmd.ServiceMark,
                    NetworkId      = netId,
                    Name           = rmd.RestaurantName,
                    Phones         = rmd.Phones,
                    Music          = rmd.Music,
                    Longitude      = ln,
                    Lattitude      = la,
                    KitchenType    = rmd.KitchenType,
                    Propositions   = rmd.Propositions,
                    ReviewText     = rmd.ReviewText,
                    SumAmount      = rmd.Amount,
                    WorkTime       = rmd.WorkHours,
                    CustomLabel    = hashtag
                });
                rdb.SaveChanges();
                message = "Successfully Saved!";
                if (Request.IsAjaxRequest())
                {
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                else
                {
                    return(null);
                }
            }
        }
Example #25
0
        public ViewResult Rating(string district, string data, string criterion, string network, int?page)
        {
            //no network selected
            if (Int32.Parse(network) == 1)
            {
                DateTime dateOFSort;
                bool     month = false;
                if (data.Equals("month"))
                {
                    month = true;
                }
                int c = Int32.Parse(criterion);
                using (restaurants_dbEntities rdb = new restaurants_dbEntities())
                {
                    var networks = rdb.networks.Select(s => new Network {
                        Id = s.Id, Name = s.Network
                    }).ToList();
                    ViewBag.Networks = networks;
                    //rating output without limitation by date
                    if (!month)
                    {//if there are limitations by district
                        if (!district.Equals("0"))
                        {
                            int distId = Int32.Parse(district);
                            var rating = rdb.restaurants.Where(x => x.DistrictId == distId).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                DistrictId   = distId,
                                Sum          = s.SumAmount
                            });
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = "";
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                        else
                        {
                            //no district limitation
                            var rating = rdb.restaurants.Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                Sum          = s.SumAmount
                            });
                            //sorting by filters
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = "";
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                    }
                    else
                    {//last month
                        dateOFSort = DateTime.Now.AddMonths(-1);
                        //as in previous case but limited by date
                        if (!district.Equals("0"))
                        {
                            int distId = Int32.Parse(district);
                            var rating = rdb.restaurants.Where(x => x.DistrictId == distId).Where(x => x.DateOfCreation >= dateOFSort).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                DistrictId   = s.Id,
                                Sum          = s.SumAmount
                            });
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = "";
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                        else
                        {
                            //any district selected
                            var rating = rdb.restaurants.Where(x => x.DateOfCreation >= dateOFSort).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                DistrictId   = s.Id,
                                Sum          = s.SumAmount
                            });
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = "";
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                    }
                }
            }
            else
            {
                //when network is selected
                int      net = Int32.Parse(network);
                DateTime dateOFSort;
                bool     month = false;
                if (data.Equals("month"))
                {
                    month = true;
                }
                int c = Int32.Parse(criterion);
                using (restaurants_dbEntities rdb = new restaurants_dbEntities())
                {
                    var networks = rdb.networks.Select(s => new Network {
                        Id = s.Id, Name = s.Network
                    }).ToList();
                    ViewBag.Networks = networks;
                    //get the name of selected network
                    var networkName = rdb.networks.Where(s => s.Id == net).Select(s => s.Network).ToList()[0];
                    //rating output without limitation by date
                    if (!month)
                    {//if there are limitations by district
                        if (!district.Equals("0"))
                        {
                            int distId = Int32.Parse(district);
                            var rating = rdb.restaurants.Where(x => x.DistrictId == distId).Where(s => s.NetworkId == net).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                DistrictId   = distId,
                                Sum          = s.SumAmount
                            });
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = networkName;
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                        else
                        {
                            //no district limitation
                            var rating = rdb.restaurants.Where(s => s.NetworkId == net).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                Sum          = s.SumAmount
                            });
                            //sorting by filters
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = networkName;
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                    }
                    else
                    {//last month
                        dateOFSort = DateTime.Now.AddMonths(-1);
                        //as in previous case but limited by date
                        if (!district.Equals("0"))
                        {
                            int distId = Int32.Parse(district);
                            var rating = rdb.restaurants.Where(x => x.DistrictId == distId).Where(s => s.NetworkId == net).Where(x => x.DateOfCreation >= dateOFSort).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                DistrictId   = s.Id,
                                Sum          = s.SumAmount
                            });
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = networkName;
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 1)));
                        }
                        else
                        {
                            //any district selected
                            var rating = rdb.restaurants.Where(x => x.DateOfCreation >= dateOFSort).Where(s => s.NetworkId == net).Select(s => new RatingModel
                            {
                                Date         = s.DateOfCreation,
                                InteriorMark = s.InteriorMark,
                                KitchenMark  = s.KitchenMark,
                                ServiceMark  = s.ServiceMark,
                                Name         = s.Name,
                                RestaurantId = s.Id,
                                DistrictId   = s.Id,
                                Sum          = s.SumAmount
                            });
                            switch (c)
                            {
                            case 1:
                                rating = rating.OrderBy(s => s.KitchenMark);
                                break;

                            case 2:
                                rating = rating.OrderBy(s => s.InteriorMark);
                                break;

                            case 3:
                                rating = rating.OrderBy(s => s.ServiceMark);
                                break;

                            case 4:
                                rating = rating.OrderBy(s => s.Sum);
                                break;
                            }
                            var sortedRating = rating.ToList();
                            var districts    = rdb.districts.Select(s => new DistrictModel {
                                Id = s.Id, District = s.District
                            }).ToList();
                            ViewBag.Districts   = districts;
                            ViewBag.NetworkName = networkName;
                            return(View("Rating", sortedRating.ToPagedList(pageNumber: page ?? 1, pageSize: 10)));
                        }
                    }
                }
            }
        }
Example #26
0
        public ActionResult EditReview(AdminSaveModel rmd)
        {
            int    id = rmd.Id;
            string message;
            string hashtag = "";

            try
            {
                //get hashtag expression
                var           regex   = new Regex(@"(?<=#)\w+");
                var           matches = regex.Matches(rmd.ReviewText);
                StringBuilder stb     = new StringBuilder();
                foreach (Match m in matches)
                {
                    stb.Append(m.Value);
                    stb.Append(" ");
                }
                if (stb[stb.Length - 1].ToString().Equals(" "))
                {
                    stb.Remove(stb.Length - 1, 1);
                }
                hashtag = stb.ToString();
            }
            catch { }
            using (restaurants_dbEntities rdb = new restaurants_dbEntities())
            {
                var rest = rdb.restaurants.Where(s => s.Id == id).FirstOrDefault();
                if (rest != null)
                {
                    rest.Address        = rmd.Address;
                    rest.Children       = rmd.Children;
                    rest.DateOfCreation = DateTime.Now;
                    rest.DistrictId     = rmd.DistrictId;
                    rest.InteriorMark   = rmd.InteriorMark;
                    rest.KitchenMark    = rmd.KitchenMark;
                    rest.ServiceMark    = rmd.ServiceMark;
                    rest.NetworkId      = rmd.NetworkId;
                    rest.Name           = rmd.RestaurantName;
                    rest.Phones         = rmd.Phones;
                    rest.Music          = rmd.Music;
                    rest.Longitude      = double.Parse(rmd.Lng.Replace('.', ','));
                    rest.Lattitude      = double.Parse(rmd.Lat.Replace('.', ','));
                    rest.KitchenType    = rmd.KitchenType;
                    rest.Propositions   = rmd.Propositions;
                    rest.ReviewText     = rmd.ReviewText;
                    rest.SumAmount      = rmd.Amount;
                    rest.WorkTime       = rmd.WorkHours;
                    rest.CustomLabel    = hashtag;
                }
                rdb.Entry(rest).State = System.Data.Entity.EntityState.Modified;
                rdb.SaveChanges();
                message = "Successfully Saved!";
                if (Request.IsAjaxRequest())
                {
                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
                else
                {
                    return(null);
                }
            }
        }