Пример #1
0
        /// <summary>
        /// Adds photo to database
        /// </summary>
        /// <param name="uploadPhotoModel"></param>
        /// <param name="mapPath"></param>
        /// <param name="username"></param>
        public void AddPhoto(UploadPhotoModel uploadPhotoModel, string mapPath, string username)
        {
            var tags = Utils.GetTagsFromText(uploadPhotoModel.Description);
            var usr = (from user in _db.Users where user.Login == username select user).ToList()[0];
            var path = SaveFile(uploadPhotoModel.PostedFile, mapPath);
            var photo = new Photo
            {
                UploadTime = DateTime.Now,
                Likes = 0,
                Dislikes = 0,
                Description = Utils.GetTaggedText(uploadPhotoModel.Description),
                Location = path,
                Tags = null,
                User = usr
            };

            var tagList = (from t in tags
                           let tag =
                _db.Tags.SingleOrDefault(T => T.Value == t.Value)
                           select tag ?? t).ToList();
            photo.Tags = tagList;
            _db.Photos.Add(photo);
            _db.SaveChanges();
        }
Пример #2
0
 public ActionResult Add(UploadPhotoModel upModel)
 {
     if (ModelState.IsValid)
         _repository.AddPhoto(upModel, Server.MapPath(" "), User.Identity.Name);
     return RedirectToAction("Index", "Home");
 }
Пример #3
0
 public ActionResult Add()
 {
     UploadPhotoModel model = new UploadPhotoModel();
     return View(model);
 }