Ejemplo n.º 1
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;
                }

            }
        }
Ejemplo n.º 2
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;
                }

            }
        }