Ejemplo n.º 1
0
        public async Task <IActionResult> UserDetails()
        {
            var account = await HttpContext.GetLoggedInUser();

            if (account == null)
            {
                return(Redirect("Index"));
            }

            var clientResponse = await _eventiApi.GetClientAsync(new ClientSearchRequest()
            {
                AccountID = account.ID
            });

            var client = clientResponse.Content.Data.ToList()[0];


            if (client == null)
            {
                return(Redirect("Index"));
            }

            ClientDetailsVM model = new ClientDetailsVM
            {
                ID          = client.ID,
                Address     = client.Address,
                Email       = client.Email,
                FirstName   = client.FirstName,
                LastName    = client.LastName,
                PhoneNumber = client.PhoneNumber,
                Image       = client.Image
            };

            var countryResponse = await _eventiApi.GetCountryAsync();

            model.Countries = countryResponse.Content.Data.ToList()
                              .Select(i => new SelectListItem {
                Text  = i.Name,
                Value = i.ID.ToString()
            })
                              .ToList();

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Save(ClientDetailsVM model, IFormFile Image)
        {
            if (!ModelState.IsValid)
            {
                var response = await _eventiApi.GetCountryAsync();

                model.Countries = response.Content.Data.Select(d => new SelectListItem
                {
                    Text  = d.Name,
                    Value = d.ID.ToString()
                }).ToList();
                return(View(model));
            }

            if (Image != null && Image.Length > 0)
            {
                var nazivSlike = Path.GetFileName(Image.FileName);
                var putanja    = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\korisnicke", nazivSlike);
                using (var fajlSteam = new FileStream(putanja, FileMode.Create))
                {
                    await Image.CopyToAsync(fajlSteam);
                }

                model.Image = nazivSlike;
            }

            await _eventiApi.UpdateClientAsync(model.ID, new ClientUpdateRequest()
            {
                FirstName        = model.FirstName,
                LastName         = model.LastName,
                Address          = model.LastName,
                Email            = model.Email,
                CreditCardNumber = model.CreditCardNumber,
                Image            = model.Image
            });

            return(Redirect("UserDetails"));
        }
Ejemplo n.º 3
0
        public IActionResult Details(int?id)
        {
            try
            {
                Client client = _context.Clients.Include(x => x.Country)
                                .Include(x => x.City)
                                .Include(x => x.ClientType)
                                .Where(x => x.ClientId == id).FirstOrDefault();

                ClientDetailsVM model = new ClientDetailsVM();

                if (_context.Appointments.Where(x => x.ClientId == id).Any())
                {
                    model = _context.AppointmentsServices.Include(x => x.Appointment)
                            .Include(x => x.Appointment.Client)
                            .Include(x => x.Service)
                            .Include(x => x.Appointment.Client.ClientType)
                            .Include(x => x.Appointment.Client.Country)
                            .Include(x => x.Appointment.Client.City)
                            .Where(x => x.Appointment.ClientId == id &&
                                   !x.IsDeleted)
                            .Select(x => new ClientDetailsVM
                    {
                        ClientId     = x.Appointment.ClientId,
                        ClientTypeId = x.Appointment.Client.ClientTypeId,
                        ClientName   = $"{x.Appointment.Client.FirstName} {x.Appointment.Client.LastName}",
                        Address      = x.Appointment.Client.Address,
                        CityName     = x.Appointment.Client.City.Name,
                        CountryName  = x.Appointment.Client.Country.Name,
                        Email        = x.Appointment.Client.Email,
                        Phone        = x.Appointment.Client.Phone,
                        TypeOfClient = x.Appointment.Client.ClientType.Name
                    }).FirstOrDefault();

                    model.CurrentMonthAppointmentsCount = _context.Appointments.Where(x => x.ClientId == (int)id &&
                                                                                      x.StartTime.Year == DateTime.Now.Year &&
                                                                                      x.EndTime.Year == DateTime.Now.Year &&
                                                                                      x.StartTime.Month == DateTime.Now.Month &&
                                                                                      x.EndTime.Month == DateTime.Now.Month &&
                                                                                      !x.IsDeleted
                                                                                      )
                                                          .Count();

                    model.TotalAppointmentsCount = _context.Appointments.Where(x => x.ClientId == (int)id)
                                                   .Count();

                    model.TotalMoneySpent = _context.AppointmentsServices.Include(x => x.Appointment)
                                            .Where(x => x.Appointment.ClientId == (int)id &&
                                                   !x.IsDeleted &&
                                                   !x.Appointment.IsDeleted)
                                            .Sum(x => x.Total);


                    model.NumberOfServicesUsed = _context.AppointmentsServices.Include(x => x.Appointment)
                                                 .Include(x => x.Service)
                                                 .Where(x => x.Appointment.ClientId == (int)id)
                                                 .Select(x => x.ServiceId)
                                                 .Count();



                    model.MostUsedService = _context.AppointmentsServices.Include(x => x.Service)
                                            .GroupBy(x => x.ServiceId)
                                            .OrderByDescending(x => x.Count())
                                            .Select(s => new
                    {
                        ServiceId = s.Key,
                        Name      = s.FirstOrDefault().Service.Name,
                        Count     = s.Count()
                    }).Take(1).FirstOrDefault().Name;
                }
                else
                {
                    model.ClientId     = client.ClientId;
                    model.ClientTypeId = client.ClientTypeId;
                    model.ClientName   = $"{client.FirstName} {client.LastName}";
                    model.Address      = client.Address;
                    model.CityName     = client.City.Name;
                    model.CountryName  = client.Country.Name;
                    model.Phone        = client.Phone;
                    model.Email        = client.Email;
                    model.TypeOfClient = client.ClientType.Name;
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                return(PartialView("Error"));
            }
        }