public async Task <ActionResult> EditPainting(PaintingUploadModel model) { try { await _paintingService.UpdateAsync(model); return(GetSuccessResponse()); } catch (Exception exception) { return(GetErrorResponse(exception)); } }
public UploadModel Upload(IEnumerable <HttpPostedFileBase> files, UploadModel listModel) { var model = HttpContext.Current.Session["Uploads"] != null ? HttpContext.Current.Session["Uploads"] as UploadModel : new UploadModel(); int maxId = 0; int order = 0; var paintings = GetPaintings().Paintings; // Если в БД уже есть фотографии, значит получаем макс. Id фотографии if (paintings.Any()) { maxId = paintings.Max(x => x.Id); order = paintings.Max(x => x.Order); } // Проверяем, имеются ли в сессии уже загруженные фотогарфии, если да, то берем за макс Id значение из сессии if (model.Uploads.Any()) { maxId = model.Uploads.Max(x => x.Id); order = model.Uploads.Max(x => x.Order); } foreach (var file in files) { var filename = $"photo_Ph-S{++maxId}"; var photoUploadModel = new PaintingUploadModel() { Id = maxId, FileName = filename, PhotoPath = AppDefaults.PhotoPath + filename + Path.GetExtension(file.FileName).ToLower(), ThumbnailPath = AppDefaults.ThumbPath + filename + "s" + Path.GetExtension(file.FileName).ToLower(), CreationDate = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now), Order = ++order }; if (file.ContentLength < 4048576) { if (file != null) { _imageProcessor.CreateThumbnail(file, 350, 350, filename); file.SaveAs(HttpContext.Current.Server.MapPath(photoUploadModel.PhotoPath)); model.Uploads.Add(photoUploadModel); HttpContext.Current.Session["Uploads"] = model; } } } return(model); }
public async Task UpdateAsync(PaintingUploadModel model) { var painting = GetPainting(model.Id); painting.TitleEn = model.TitleEng; painting.TitleRu = model.TitleRu; painting.DescriptionEn = model.DescriptionEng; painting.DescriptionRu = model.DescriptionRu; painting.Order = model.Order; await _paintigRepository.UpdateAsync(painting); if (model.CategoryId != default(int)) { await _paintingCategoryRepository.RemoveCategories(painting.Id); await _paintingCategoryRepository.AddCategory(new PaintingCategories() { PaintingId = painting.Id, CategoryId = model.CategoryId }); } }
public ActionResult EditUploadPhoto(PaintingUploadModel model) { try { var list = Session["Uploads"] as UploadModel; for (int i = 0; i < list.Uploads.Count; i++) { if (list.Uploads[i].Id == model.Id) { list.Uploads[i] = model; } } Session["Uploads"] = list; } catch (Exception exception) { Logger.LogError(exception); } return(RedirectToAction("UploadPainting")); }
public PaintingUploadModel GetEditModel(int id) { var photo = GetPainting(id); var category = _paintingCategoryRepository.GetAllCategories(id).FirstOrDefault(); var model = new PaintingUploadModel() { Id = photo.Id, Order = photo.Order, PhotoPath = photo.Path, ThumbnailPath = photo.ThumbPath, CreationDate = photo.Created, FileName = photo.FileName, TitleRu = photo.TitleRu, TitleEng = photo.TitleEn, DescriptionEng = photo.DescriptionEn, DescriptionRu = photo.DescriptionRu, Action = "EditPainting", Categories = _categoryService.BuildCategories(), CategoryId = category?.CategoryId ?? default(int) }; return(model); }