Ejemplo n.º 1
0
        public void DeleteOne(int id)
        {
            var photoToTags = _providerPhotoToTag.GetAll().Where(x => x.TagId == id).ToList();

            if (photoToTags.Count() > 0)
            {
                _providerPhotoToTag.DeleteMany(photoToTags.Select(x => x.Id).ToArray());
            }

            _providerTag.DeleteOne(id);
            _providerTag.Commit();
        }
Ejemplo n.º 2
0
        public Photo UpdateOne(PhotoUploadModel model, HttpPostedFileBase file, IImageProcessor processor)
        {
            var photoToTags   = _providerPhotoToTag.GetAll();
            var relatedTagIds = photoToTags.GetRelatedTags(model.Id).Select(x => x.Id).ToArray();

            if (relatedTagIds.Length > 0)
            {
                _providerPhotoToTag.DeleteMany(relatedTagIds);
                _providerPhoto.Commit(); //TODO: продумать
            }

            if (file != null)
            {
                if (file.ContentLength != 0 && file.ContentLength < 4048576)
                {
                    processor.CreateThumbnail(file, 350, 350, model.FileName);
                    file.SaveAs(HttpContext.Current.Server.MapPath(model.PhotoPath));
                }
            }

            var photos = _providerPhoto.UpdateOne(_converter.ConvertTo(model));

            _providerWatermark.UpdateOne(_converterWatermark.ConvertTo(model.ImageAttributes));

            if (model.RelatedTagIds != null)
            {
                _providerPhotoToTag.AddMany(model.RelatedTagIds
                                            .Select(x => new PhotoToTag()
                {
                    Id      = 0,
                    PhotoId = model.Id,
                    TagId   = x
                }).ToArray()
                                            );
            }

            _providerPhoto.Commit();

            return(photos);
        }