Exemplo n.º 1
0
        public async Task <ActionResult> ShowRecensionForLocation(Guid lokacija)
        {
            ApplicationDbContext dbCtx        = ApplicationDbContext.Create();
            Location             lokacijaCela = dbCtx.Locations.Include(x => x.ProjectionsList).FirstOrDefault(x => x.Id == lokacija);
            // HallTimeProjection projekcija = dbCtx.HallTimeProjection.Include(x => x.Projection).FirstOrDefault(x => x.Id == rezKarta.Projection.Id);
            string id = User.Identity.GetUserId();



            List <Recension> recenzije = dbCtx.Recensions.ToList();

            foreach (Recension r in recenzije)
            {
                Recension re  = dbCtx.Recensions.Include(x => x.RecensionUser).FirstOrDefault(x => x.Id == r.Id);
                Recension rec = dbCtx.Recensions.Include(x => x.location).FirstOrDefault(x => x.Id == re.Id);
                if (rec.location != null)
                {
                    if (re.location.Id.Equals(rec.location.Id) && re.RecensionUser.Id.Equals(id))
                    {
                        return(View("AlreadyGaveRecensionLocation", rec));
                    }
                }
            }

            return(View("ShowRecensionForLocation", lokacijaCela));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ShowRecension(Guid rezervacija)
        {
            ApplicationDbContext dbCtx    = ApplicationDbContext.Create();
            Ticket             rezKarta   = dbCtx.Reservations.Include(x => x.Projection).FirstOrDefault(x => x.Id == rezervacija);
            HallTimeProjection projekcija = dbCtx.HallTimeProjection.Include(x => x.Projection).FirstOrDefault(x => x.Id == rezKarta.Projection.Id);
            string             id         = User.Identity.GetUserId();

            Guid idproj = projekcija.Projection.Id;

            List <Recension> recenzije = dbCtx.Recensions.ToList();

            foreach (Recension r in recenzije)
            {
                Recension re = dbCtx.Recensions.Include(x => x.RecensionUser).FirstOrDefault(x => x.Id == r.Id);
                if (re.projection != null)
                {
                    if (re.projection.Id.Equals(idproj) && re.RecensionUser.Id.Equals(id))
                    {
                        return(View("AlreadyGaveRecensionProjection", r));
                    }
                }
            }

            return(View("ShowRecension", projekcija.Projection));
        }
Exemplo n.º 3
0
        public JsonResult RateProjection(String[] arr)
        {
            ApplicationDbContext dbCtx = ApplicationDbContext.Create();
            Guid idProjekcije          = new Guid(arr[0]);
            int  ocena = -1;

            int.TryParse(arr[1], out ocena);
            Projection projekcija = dbCtx.Projections.Include(x => x.ProjHallsTimeList).FirstOrDefault(x => x.Id == idProjekcije);
            string     userId     = User.Identity.GetUserId();
            var        reserver   = dbCtx.Users.Include(x => x.RecensionList).FirstOrDefault(x => x.Id == userId);

            Recension newRecension = new Recension
            {
                location         = null,
                projection       = projekcija,
                RatingLocation   = -1,
                RatingProjection = ocena,
                RecensionUser    = reserver
            };

            reserver.RecensionList.Add(newRecension);
            dbCtx.Recensions.Add(newRecension);
            dbCtx.SaveChanges();
            var    recenzije = dbCtx.Database.SqlQuery <Recension>("select * from Recensions where projection_Id = '" + projekcija.Id + "'").ToList();
            double suma      = 0;

            foreach (Recension rec in recenzije)
            {
                suma += rec.RatingProjection;
            }
            double prosecna = suma / recenzije.Count;

            projekcija.AvgRating = prosecna;
            dbCtx.SaveChanges();
            var obj = new
            {
                tr = true
            };

            return(Json(obj));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Uppdaterar en post.
        /// </summary>
        /// <param name="contact">Posten som ska uppdateras.</param>
        public void UpdateReview(Recension toEdit)
        {
            using (var con = CreateConnection())
            {
                try
                {
                    var cmd = new SqlCommand("appSchema.usp_UpdateReview", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@RecID", SqlDbType.Int, 4).Value            = toEdit.RecID;
                    cmd.Parameters.Add("@FilmID", SqlDbType.Int, 4).Value           = toEdit.FilmID;
                    cmd.Parameters.Add("@MedlemID", SqlDbType.Int, 4).Value         = toEdit.MedlemID;
                    cmd.Parameters.Add("@Recension", SqlDbType.NVarChar, 150).Value = toEdit.Recensionen;

                    con.Open();
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    throw new ApplicationException("Ett fel uppstod i samband med uppkopplingen mot databasen.");
                }
            }
        }
        public void AddRecension(Recension toAdd)
        {
            var validationContext = new ValidationContext(toAdd);
            var validationResults = new List <ValidationResult>();

            if (!Validator.TryValidateObject(toAdd, validationContext, validationResults))
            {
                var ex = new ValidationException("Objektet klarade inte valideringen.");
                ex.Data.Add("ValidationResults", validationResults);
                throw ex;
            }

            //if (toAdd.RecID == 0)
            //{
            //    RecDAL.AddReview(toAdd);
            //}
            //else
            //{
            //    RecDAL.AddReview(toAdd);
            //}
            RecDAL.AddReview(toAdd);
        }