public async Task <IActionResult> ConfirmWorkshopAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var workshop = await _context.WorkShops.FindAsync(id);

            if (workshop == null)
            {
                return(NotFound());
            }

            string message;

            try
            {
                workshop.Verified = true;
                await _context.SaveChangesAsync();

                message = $"Workshop \"{workshop.Name}\" confirmed successfully";
            }
            catch
            {
                message = $"Can't confirm workshop \"{workshop.Name}\", something went wrong";
            }

            return(Content(message));
        }
        public async Task <IActionResult> UserRate(WorkshopRate WorkshopRate)
        {
            var workShop = await _context.WorkShops.FindAsync(WorkshopRate.WorkShopId);

            try
            {
                var userID      = _httpContext.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var userprofile = _context.UserProfiles.Where(p => p.UserId == userID).FirstOrDefault();

                WorkshopRate.UserProfileId = userprofile.Id;

                _context.WorkshopRates.Add(WorkshopRate);

                //calculate rate
                var Rates = await _context.WorkshopRates.Where(w => w.WorkShopId == WorkshopRate.WorkShopId).ToListAsync();

                double rate = 0;

                foreach (var item in Rates)
                {
                    rate += (double)item.Rate;
                }

                double total = rate / Rates.Count;

                workShop.Rate = (double)total;


                await _context.SaveChangesAsync();


                return(RedirectToAction("Details", new { id = workShop.Id }));
            }
            catch (Exception)
            {
                return(RedirectToAction("Details", new { id = workShop.Id }));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            var workshop = _context.WorkShops.Where(w => w.UserId == UserId).FirstOrDefault();

            if (ModelState.IsValid)
            {
                //set work shop Location
                var government = _context.Governments.Where(g => g.Name == Government).FirstOrDefault();
                var city       = _context.Cities.Where(c => c.Name == City && c.GovernmentId == government.Id).FirstOrDefault();

                workshop.City    = city;
                workshop.Address = Street;

                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./WorkshopComplete"));
        }
        public async Task <IActionResult> Create(ServicesViewModel servicesViewModel)
        {
            try
            {
                var userID   = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var workshop = await _context.WorkShops
                               .FirstOrDefaultAsync(w => w.User.Id == userID);

                string ImgaeFileName = null;
                if (servicesViewModel.Imagepath != null)
                {
                    string uploads = Path.Combine(hosting.WebRootPath, "Upload/images");

                    ImgaeFileName = servicesViewModel.Imagepath.FileName;
                    string uniqueFileName = Guid.NewGuid().ToString() + "_" + ImgaeFileName;

                    string   ImageFullPath = Path.Combine(uploads, uniqueFileName);
                    FileInfo file          = new(ImageFullPath);

                    if (file.Exists.Equals(false))
                    {
                        servicesViewModel.Imagepath.CopyTo(new FileStream(ImageFullPath, FileMode.Create));
                    }
                }

                Service service = new()
                {
                    Title       = servicesViewModel.Title,
                    Price       = servicesViewModel.Price,
                    Description = servicesViewModel.Description,
                    Verified    = servicesViewModel.Verified,
                    Image       = ImgaeFileName,
                    WorkShopId  = workshop.Id
                };

                if (ModelState.IsValid)
                {
                    await _context.Services.AddAsync(service);

                    //send notification to workshop
                    _context.Notifications.Add(new Notification
                    {
                        ReceiverId = userID,
                        Type       = "AddService",
                        ContentId  = service.Id,
                    });

                    await _context.SaveChangesAsync();

                    TempData["Done"] = "Created sucessfully";
                }
            }
            catch (UnauthorizedAccessException)
            {
                return(RedirectToAction(nameof(DisplayServices)));
            }
            catch (Exception)
            {
                TempData["Done"] = "Service doesn't created Sucessfully";
            }

            return(RedirectToAction(nameof(DisplayServices)));
        }