Esempio n. 1
0
        public ProcessResult AddPlace(Place place, HttpPostedFileBase imageUpload, HttpServerUtilityBase server)
        {
            if (Translation.IsInValid(place.Translation) || Translation.IsInValid(place.Translation1))
                return ProcessResults.InvalidTranslations;
            if (GetPlace(place.Translation, place.RegionId) != null)
                return ProcessResults.PlaceAlreadyExists;
            var t = Data.Translations.Add(place.Translation);
            Data.SaveChanges();
            place.Name = t.Id;
            t = Data.Translations.Add(t);
            Data.SaveChanges();
            place.Description = t.Id;
            place = Data.Places.Add(place);
            try
            {
                Data.SaveChanges();
            }
            catch (Exception)
            {
                Data.Places.Remove(place);
                Data.SaveChanges();
                return ProcessResults.Error;
            }

            if (imageUpload != null)
            {
                if (imageUpload.ContentLength <= 0 || !SecurityManager.IsImage(imageUpload))
                    return ProcessResults.InvalidImageFormat;
                place.Image = SaveImage(place.Id, StaticSettings.PlacesUploadFolderPath, imageUpload, server);
                Data.SaveChanges();
            }
            ProcessResult result = ProcessResults.PlaceAdded;
            result.AffectedObjectId = place.Id;
            return result;
        }
 public ActionResult ManagePlaceEditing(Place place, HttpPostedFileBase imageUpload, bool deleteImage = false)
 {
     var user = DefineUser(HttpContext);
     if (HasNoAccess(user)) return RedirectToAction("NoPermission");
     ProcessResult result = DataManager.Places.EditPlace(place, deleteImage,imageUpload,Server);
     if (result.Succeeded)
         return RedirectToAction("Place", new { placeId = place.Id, result = result.Id });
     return RedirectToAction("EditPlace", new { placeId = place.Id, result = result.Id });
 }
Esempio n. 3
0
 public ProcessResult EditPlace(Place place, bool deleteImage, HttpPostedFileBase imageUpload, HttpServerUtilityBase server)
 {
     if (Translation.IsInValid(place.Translation) || Translation.IsInValid(place.Translation1))
         return ProcessResults.TitleCannotBeEmpty;
     var p = GetPlace(place.Translation, place.RegionId);
     if (p != null && p.Id != place.Id)
         return ProcessResults.PlaceAlreadyExists;
     p = GetPlace(place.Id);
     if (p == null)
         return ProcessResults.PlaceNotFound;
     p.Translation.En = place.Translation.En;
     p.Translation.Ru = place.Translation.Ru;
     p.Translation1.En = place.Translation1.En;
     p.Translation1.Ru = place.Translation1.Ru;
     p.TypeId = place.TypeId;
     p.X = place.X;
     p.Y = place.Y;
     if (deleteImage && imageUpload == null)
     {
         DeleteImage(p.Image, server);
     }
     else if (imageUpload != null)
     {
         if (imageUpload.ContentLength <= 0 || !SecurityManager.IsImage(imageUpload))
             return ProcessResults.InvalidImageFormat;
         p.Image = SaveImage(place.Id, StaticSettings.PlacesUploadFolderPath, imageUpload, server);
     }
     Data.SaveChanges();
     return ProcessResults.PlaceEdited;
 }
 public ActionResult ManagePlaceAdding(Place place, HttpPostedFileBase imageUpload)
 {
     var user = DefineUser(HttpContext);
     if (HasNoAccess(user)) return RedirectToAction("NoPermission");
     ProcessResult result = DataManager.Places.AddPlace(place,imageUpload, Server);
     if (result.Succeeded && result.AffectedObjectId.HasValue)
         return RedirectToAction("Place", new { placeId = result.AffectedObjectId.Value, result = result.Id });
     return RedirectToAction("AddPlace", new { result = result.Id, regionId = place.RegionId });
 }