public ActionResult AddOpinion(OpinionVM model)
        {
            if (ModelState.IsValid)
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    Opinion opinion = new Opinion
                    {
                        Description   = model.Description,
                        CompanyId     = model.CompanyId,
                        GradeValue    = model.GradeValue,
                        ReservationId = model.ReservationId
                    };
                    db.Opinions.Add(opinion);
                    db.SaveChanges();
                }
                return(RedirectToAction("MyReservation"));
            }

            return(View(model));
        }
        public ActionResult AddOpinion(int idTerm)
        {
            var user  = User as MPrincipal;
            var login = user.UserDetails.Login;

            ViewBag.UserName = user.UserDetails.Login;
            ViewBag.UserRole = 3;

            OpinionVM opinion = new OpinionVM();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var term = db.Terms.FirstOrDefault(u => u.Id.Equals(idTerm));
                var comp = db.Companies.FirstOrDefault(c => c.Id == term.CompanyId);
                var res  = db.Reservations.FirstOrDefault(r => r.TermId == idTerm);
                opinion.CompanyId     = comp.Id;
                opinion.CompanyName   = comp.CompanyName;
                opinion.ReservationId = res.Id;
            }
            return(View(opinion));
        }
Beispiel #3
0
        public ActionResult OpinionAcceptList()
        {
            var user  = User as MPrincipal;
            var login = user.UserDetails.Login;

            ViewBag.UserName = user.UserDetails.Login;
            ViewBag.UserRole = 5;
            List <OpinionVM> opinionList = new List <OpinionVM>();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var opinions = db.Opinions.Where(o => o.AdminAccept == false && o.IsDelete == false).ToList();
                foreach (var item in opinions)
                {
                    OpinionVM opinionVM = new OpinionVM()
                    {
                        Description = item.Description,
                        Id          = item.Id,
                    };
                    opinionList.Add(opinionVM);
                }
            }
            return(View(opinionList));
        }
Beispiel #4
0
        public static CompanyInfoVM CompanyInfo(int companyId)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                var company = db.Companies.SingleOrDefault(x => x.Id == companyId);

                List <Tag> tagList = new List <Tag>();
                tagList = db.Tags.Where(t => t.CompanyTag.Any(c => c.CompanyId == company.Id)).ToList();

                bool tagExist = false;
                if (tagList != null)
                {
                    tagExist = true;
                }

                List <CompanyTermVM> compTermList = Controllers.TermController.CompanyTermToList(company.Id).Where(c => c.Actual == true && c.CustomerID == null).ToList();

                CompanyTermVM nearestTerm = compTermList.FirstOrDefault(t => t.DateStart > DateTime.Now);

                string nearestFreeTerm = "Brak wolnych terminów";
                if (nearestTerm != null)
                {
                    nearestFreeTerm = nearestTerm.DateStart.ToShortDateString();
                }

                List <Image> imageList = new List <Image>();
                imageList = db.Images.Where(t => t.CompanyId == company.Id && t.IsDelete == false).ToList();

                Image imageMain = new Image();
                imageMain = db.Images.FirstOrDefault(i => i.CompanyId == company.Id && i.MainPicture == true);
                if (imageMain == null)
                {
                    imageMain = new Image()
                    {
                        Link = "~/Content/images/brakZdj.jpg"
                    };
                }
                var opinionList = db.Opinions.Where(o => o.CompanyId == company.Id && o.IsDelete == false && o.AdminAccept == true).ToList();
                List <OpinionVM> opinionListVM = new List <OpinionVM>();

                List <int> gradeValues = new List <int>();

                for (int i = 0; i < opinionList.Count(); i++)
                {
                    var       customName = opinionList[i].Reservation.Term.Customer.Name + " " + opinionList[i].Reservation.Term.Customer.Surname;
                    OpinionVM opinionVM  = new OpinionVM
                    {
                        Description  = opinionList[i].Description,
                        CustomerName = customName,
                        GradeValue   = opinionList[i].GradeValue
                    };
                    opinionListVM.Add(opinionVM);
                    gradeValues.Add(opinionList[i].GradeValue);
                }

                double average = 0;
                if (gradeValues.Count > 0)
                {
                    average = gradeValues.Average();
                }


                CompanyInfoVM companyInfoVM = new CompanyInfoVM()
                {
                    IdCompany          = company.Id,
                    CityName           = company.City.Name,
                    CompanyName        = company.CompanyName,
                    Speciality         = company.Speciality,
                    Services           = company.Services,
                    Pricing            = company.Pricing,
                    PhoneNumer         = company.PhoneNumer,
                    CompanyTagList     = tagList,
                    CompanyTermVMList  = compTermList,
                    CompanyImageList   = imageList,
                    TagExist           = tagExist,
                    NearestFreeDate    = nearestFreeTerm,
                    CompanyMainImage   = imageMain,
                    CompanyOpinionList = opinionListVM,
                    AverageRating      = average,
                    OpinionsCount      = opinionListVM.Count()
                };
                return(companyInfoVM);
            };
        }