Exemplo n.º 1
0
 /// <summary>
 /// Changes the rating.
 /// </summary>
 /// <param name="manual">The manual.</param>
 /// <param name="liked">if set to <c>true</c> [liked].</param>
 /// <returns></returns>
 public bool? ChangeRating(ManualViewModel manual, bool liked)
 {
     Rating rating = unitOfWork.RatingRepository.Get(filter: e => e.UserId == currentUserId && e.ManualId == manual.Id)
         .FirstOrDefault();
     if (rating == null)
     {
         unitOfWork.RatingRepository.Add(new Rating
         {
             ManualId = manual.Id,
             UserId = currentUserId,
             Liked = liked
         });
         unitOfWork.Save();
         return liked;
     }
     else if (rating.Liked != liked)
     {
         if (rating.Liked == null)
         {
             rating.Liked = liked;
         }
         else
         {
             rating.Liked = null;
         }
         unitOfWork.RatingRepository.Update(rating);
     }
     unitOfWork.Save();
     return rating.Liked;
 }
Exemplo n.º 2
0
 public ActionResult ChangeRating(ManualViewModel manual, bool liked)
 {
     if (User.Identity.IsAuthenticated)
     {
         bool? voted = manualService.ChangeRating(manual, liked);
         int rating = manualService.CountRating(manual.Id);
         return Json(new { result = "success", newRating = rating, voted = voted });
     }
     return Json(new { result = "error" });
 }
Exemplo n.º 3
0
 public ActionResult CreateNewManual(ManualViewModel model, string ReturnUrl = "/")
 {
     if (ModelState.IsValid)
     {
         var currentUserId = User.Identity.GetUserId();
         model.UserId = currentUserId;
         model.DateAdded = DateTime.Now;
         Manual manual = Mapper.Map<Manual>(model);
         manualRepository.Add(manual);
         manualRepository.Save();
         return Json(new { result = "Redirect", url = ReturnUrl });
     }
     return View(model);
 }
Exemplo n.º 4
0
 private Manual MapManualToDAL(ManualViewModel manual)
 {
     Manual manualDAL = Mapper.Map<Manual>(manual);
     if (manual.Tags != null)
     {
         foreach (var tag in manual.Tags)
         {
             Tag tagEntity = unitOfWork.TagRepository.GetById(tag.Id);
             manualDAL.Tags.Add(tagEntity);
         }
     }
     if (manual.Category != null)
     {
         Category category = unitOfWork.CategoryRepository.GetById(manual.Category.Id);
         manualDAL.Category = category;
     }
     return manualDAL;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Saves the manual.
 /// </summary>
 /// <param name="model">The model.</param>
 public void SaveManual(ManualViewModel model)
 {
     model.ImageLink = imageService.UploadImage(model.ImageLink);
     Manual manual = MapManualToDAL(model);
     if (manual.Id != 0)
     {
         unitOfWork.ManualRepository.Update(manual);
     }
     else
     {
         manual.UserId = currentUserId;
         manual.DateAdded = DateTime.Now;
         unitOfWork.ManualRepository.Add(manual);
     }
     unitOfWork.Save();
     searchService.AddNewManualToIndex(manual);
 }
Exemplo n.º 6
0
 public ActionResult CreateNewManual(string ReturnUrl)
 {
     ManualViewModel model = new ManualViewModel();
     ViewBag.ReturnUrl = ReturnUrl;
     return View(model);
 }
Exemplo n.º 7
0
        private void CalculateRating(ManualViewModel manual,string userId, bool liked)
        {
            Rating rating = ratingRepository.GetAll()
                .FirstOrDefault(e => e.UserId == userId && e.ManualId == manual.Id);
            if (rating == null)
            {
                ratingRepository.Add(new Rating
                {
                    ManualId = manual.Id,
                    UserId = userId,
                    Liked = liked
                });
            }
            else if (rating.Liked != liked)
            {
                if (rating.Liked == null)
                {
                    rating.Liked = liked;
                }
                else
                {
                    rating.Liked = null;
                }
                ratingRepository.Update(rating);
            }
            ratingRepository.Save();

        }
Exemplo n.º 8
0
 public ActionResult ChangeRating(ManualViewModel manual, bool liked)
 {
     string currentUserId = User.Identity.GetUserId();
     CalculateRating(manual,currentUserId, liked);
     int rating = GetRating(manual.Id);
     return Json(new { newRating = rating });
 }
Exemplo n.º 9
0
        public ActionResult DeleteManual(ManualViewModel manual)
        {
           if (User.IsInRole("Admin") || manual.UserId == User.Identity.GetUserId())
            {
                manualRepository.Delete(manual.Id);
                manualRepository.Save();


            }

            return null;
        }
Exemplo n.º 10
0
 public ActionResult CreateNewManual(ManualViewModel model, string ReturnUrl = "/")
 {
     if (ModelState.IsValid)
     {
         var currentUserId = User.Identity.GetUserId();
         model.UserId = currentUserId;
         model.DateAdded = DateTime.Now;
        if (model.TemplateId==3) model.VideoLink = model.VideoLink.Substring(model.VideoLink.IndexOf("v=")+2, 11); 
         Manual manual = Mapper.Map<Manual>(model);
         manualRepository.Add(manual);
         manualRepository.Save();
         MedalsCheck();
         return Json(new { result = "Redirect", url = ReturnUrl });
     }
     return View(model);
 }
Exemplo n.º 11
0
 public ActionResult SaveManual(ManualViewModel model)
 {
     if (ModelState.IsValid)
     {
         manualService.SaveManual(model);
         return Json(new { result = "redirect" });
     }
     return JsonFormResponse();
 }