예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public PlaceModel(Place model)
 {
     id = model.Id;
     title = model.Title;
     address = model.Address;
     img = model.Image;
     objType = "place";
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public PlaceDetailsModel(Place model)
     : base(model)
 {
     description = model.Description;
     phone1 = model.Phone1;
     phone2 = model.Phone2;
     phone3 = model.Phone3;
     fax = model.Fax;
     site = model.Site;
     email = model.Email;
     lat = model.Latitude;
     lon = model.Longitude;
     work_time = model.WorkTime;
     cash = model.CashPayments;
     cashless = model.CashlessPayments;
     booking = model.Booking;
     ordering = model.Ordering;
     wifi = model.WiFi;
     vip = model.VIPSection;
     liveMusic = model.LiveMusic;
     businessLunch = model.BusinessLunch;
     check = model.AverageCheck;
 }
예제 #3
0
        public ActionResult Save(Place model)
        {
            var file = Request.Files["Image"];
            string imageUrl = null;
            if (file != null && file.ContentLength > 0 && file.ContentType.ToLower().Contains("image"))
            {
                var fileName = Path.ChangeExtension(Path.GetRandomFileName(), ".jpg");
                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", "Places");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                var fullPath = Path.Combine(path, fileName);
                ImageHelper.SaveAs(file, fullPath);
                imageUrl = "/Files/Places/" + fileName;
            }

            if (model.Id <= 0)
            {
                model.DateCreated = DateTime.Now;
                model.Image = imageUrl;
                Repository.Add(model);
                Repository.SubmitChanges();
                ShowSuccess("Заведение успешно добавлено");
            }
            else
            {
                // Ищем
                var place = Repository.Load(model.Id);
                if (place == null)
                {
                    ShowError("Такое заведение не найдено");
                    return RedirectToAction("Index");
                }

                // Пытаемся обновить
                var oldImage = place.Image;
                var oldCityId = place.CityId;
                var oldCategoryId = place.CategoryId;
                TryUpdateModel(place);
                if (oldCityId != place.CityId)
                {
                    // TODO: нужно реализовать репозиторий категорий
                }
                if (oldCategoryId != place.CategoryId)
                {
                    var newCategory = Locator.GetService<ICategoriesRepository>().Load(place.CategoryId);
                    place.Category.Places.Remove(place);
                    if (newCategory != null)
                    {
                        newCategory.Places.Add(place);
                    }
                }
                place.DateModified = DateTime.Now;
                place.Image = imageUrl ?? oldImage;
                Repository.SubmitChanges();

                ShowSuccess("Заведение успешно отредактировано");
            }

            return RedirectToAction("Index");
        }
예제 #4
0
		private void detach_Places(Place entity)
		{
			this.SendPropertyChanging();
			entity.City = null;
		}
예제 #5
0
		private void attach_Places(Place entity)
		{
			this.SendPropertyChanging();
			entity.City = this;
		}