Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,MediaId,Rating")] MediaRating mediaRating)
        {
            if (ModelState.IsValid)
            {
                string          currentUserId = User.Identity.GetUserId();
                ApplicationUser currentUser   = db.Users.FirstOrDefault(x => x.Id == currentUserId);


                var zz = db.MediaRatings.Where(x => x.UserId == currentUserId);
                var yy = zz.Where(x => x.MediaId == mediaRating.MediaId);

                mediaRating.UserId = currentUserId;

                if (yy.FirstOrDefault() != null)
                {
                    MediaRating oldNewMediaRating = yy.FirstOrDefault();
                    oldNewMediaRating.Rating = mediaRating.Rating;

                    db.Entry(oldNewMediaRating).State = EntityState.Modified;
                }
                else
                {
                    db.MediaRatings.Add(mediaRating);
                }


                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MediaId = new SelectList(db.TextPieces, "Id", "Title", mediaRating.MediaId);
            ViewBag.UserId  = new SelectList(db.ApplicationUsers, "Id", "Email", mediaRating.UserId);
            return(View(mediaRating));
        }
        private void DisplayData()
        {
            RatingsList = video.MediaRatings.ToList();
            PM          = GetRatingRow("Physical Masculine");
            PF          = GetRatingRow("Physical Feminine");
            EM          = GetRatingRow("Emotional Masculine");
            EF          = GetRatingRow("Emotional Feminine");
            SM          = GetRatingRow("Spiritual Masculine");
            SF          = GetRatingRow("Spiritual Feminine");
            Love        = GetRatingRow("Love");
            Egoless     = GetRatingRow("Egoless");
            var CustomCategories = video.MediaRatings.Where(r => r.RatingCategory.Custom).OrderBy(r => r.RatingCategory.Name);

            Custom1 = CustomCategories.FirstOrDefault();
            if (Custom1 != null)
            {
                Custom2 = CustomCategories.Skip(1).FirstOrDefault();
            }
            if (Custom1 != null)
            {
                Custom1Text = Custom1.RatingCategory.Name;
            }
            else
            {
                Custom1 = new MediaRating();
            }
            if (Custom2 != null)
            {
                Custom2Text = Custom2.RatingCategory.Name;
            }
            else
            {
                Custom2 = new MediaRating();
            }
        }
Ejemplo n.º 3
0
        private void CreateToolTip(TextBlock ctrl, MediaRating rating)
        {
            if (rating.Height.HasValue || rating.Depth.HasValue)
            {
                ToolTip NewToolTip = new ToolTip();
                ctrl.ToolTip = NewToolTip;
                StackPanel NewPanel = new StackPanel();
                NewToolTip.Content = NewPanel;
                TextBlock NewTextBlock = new TextBlock();
                NewTextBlock.TextAlignment = TextAlignment.Center;
                NewPanel.Children.Add(NewTextBlock);

                if (rating.Height.HasValue)
                {
                    NewTextBlock.Inlines.Add(new Run("Height: " + rating.Height.Value));
                    NewTextBlock.Inlines.Add(new LineBreak());
                }
                if (rating.Depth.HasValue)
                {
                    NewTextBlock.Inlines.Add(new Run("Depth: " + rating.Depth.Value));
                    NewTextBlock.Inlines.Add(new LineBreak());
                }
                NewTextBlock.Inlines.Add(new Run(string.Format("{0} × {1} × 0.11 = {2:0.0}",
                                                               rating.Height.HasValue ? rating.Height.Value : rating.Depth.Value,
                                                               rating.Depth.HasValue ? rating.Depth.Value : rating.Height.Value,
                                                               rating.GetValue(0))));
            }
            else
            {
                ctrl.ToolTip = null;
            }
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            MediaRating mediaRating = db.MediaRatings.Find(id);

            db.MediaRatings.Remove(mediaRating);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public static void DisplayValue(TextBlock obj, MediaRating rating, double ratio)
        {
            RatingConverter        Conv      = new RatingConverter();
            RatingToColorConverter ColorConv = new RatingToColorConverter();
            double?Value = rating.GetValue(ratio);

            obj.Text       = Conv.Convert(Value, typeof(string), -1, null).ToString();
            obj.Foreground = (SolidColorBrush)ColorConv.Convert(Value, typeof(SolidColorBrush), null, null);
        }
        public MediaRating GetRatingRow(string ratingName)
        {
            MediaRating Result = RatingsList.Where(r => r.RatingCategory.Name == ratingName).FirstOrDefault();

            if (Result == null)
            {
                Result = new MediaRating();
            }
            return(Result);
        }
Ejemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "Id,MediaId,Rating,UserId")] MediaRating mediaRating)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mediaRating).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MediaId = new SelectList(db.TextPieces, "Id", "Title", mediaRating.MediaId);
     ViewBag.UserId  = new SelectList(db.ApplicationUsers, "Id", "Email", mediaRating.UserId);
     return(View(mediaRating));
 }
Ejemplo n.º 8
0
        // GET: MediaRatings/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MediaRating mediaRating = db.MediaRatings.Find(id);

            if (mediaRating == null)
            {
                return(HttpNotFound());
            }
            return(View(mediaRating));
        }
Ejemplo n.º 9
0
        // GET: MediaRatings/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MediaRating mediaRating = db.MediaRatings.Find(id);

            if (mediaRating == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MediaId = new SelectList(db.TextPieces, "Id", "Title", mediaRating.MediaId);
            ViewBag.UserId  = new SelectList(db.ApplicationUsers, "Id", "Email", mediaRating.UserId);
            return(View(mediaRating));
        }
 public void AddRating(string name, MediaRating rating, List <RatingCategory> categories)
 {
     if (!string.IsNullOrEmpty(name) && (rating.Height.HasValue || rating.Depth.HasValue))
     {
         RatingCategory Rating = categories.Find(c => c.Name.ToLower() == name.ToLower());
         //if (Rating == null) {
         //    Rating = new RatingCategory() { Name = name, Custom = true };
         //    context.RatingCategories.Add(Rating);
         //}
         if (Rating != null)
         {
             video.MediaRatings.Add(new MediaRating()
             {
                 RatingCategory = Rating, Height = rating.Height, Depth = rating.Depth
             });
         }
     }
 }
Ejemplo n.º 11
0
        public Media ConvertToMedia(List <MediaCategory> mediaCategories, List <RatingCategory> ratingCategories)
        {
            Media Result = new Media();

            Result.MediaId   = MediaId != Guid.Empty ? MediaId : Guid.NewGuid();
            Result.EditedOn  = EditedOn ?? DateTime.Now;
            Result.MediaType = MediaType;
            Result.Artist    = Artist ?? string.Empty;
            Result.Album     = Album ?? string.Empty;
            Result.Title     = Title;
            if (!string.IsNullOrEmpty(Category))
            {
                MediaCategory ItemCategory = mediaCategories.FirstOrDefault(v => v.Name == Category && v.MediaTypeId == (int)MediaType);
                if (ItemCategory != null)
                {
                    Result.MediaCategoryId = ItemCategory.MediaCategoryId;
                }
            }
            Result.Preference   = Preference;
            Result.Length       = Length;
            Result.StartPos     = StartPos;
            Result.EndPos       = EndPos;
            Result.DownloadName = DownloadName ?? string.Empty;
            Result.DownloadUrl  = DownloadUrl ?? string.Empty;
            Result.BuyUrl       = BuyUrl ?? string.Empty;

            MediaRating NewRating;

            foreach (SyncRating item in Ratings)
            {
                NewRating          = new MediaRating();
                NewRating.MediaId  = Result.MediaId;
                NewRating.RatingId = ratingCategories.FirstOrDefault(r => r.Name == item.Name).RatingId;
                NewRating.Height   = (item.Height != -1 ? (double?)item.Height : null);
                NewRating.Depth    = (item.Depth != -1 ? (double?)item.Depth : null);
                Result.MediaRatings.Add(NewRating);
            }

            return(Result);
        }