Exemplo n.º 1
0
        public ApiResultModel <dynamic> CreateCustomer(CustomerDetailsViewModel customer)
        {
            ApiResultModel <dynamic> apiResult;

            try
            {
                customer.CreatedDate  = DateTime.Now;
                customer.ModifiedDate = DateTime.Now;
                CustomerDetail customerDetails = Mapper.Map <CustomerDetail>(customer);
                db.CustomerDetails.Add(customerDetails);
                db.SaveChanges();
                apiResult = PrepareReturnResult(ApiConstants.CustomerCreatedSuccessfully, isSuccess: true);
            }
            catch (DbEntityValidationException)
            {
                apiResult = PrepareReturnResult(ApiConstants.InvalidInputs);
            }
            catch (Exception ex)
            {
                if (IsDuplicateEmailIdException(ex))
                {
                    apiResult = PrepareReturnResult(ApiConstants.DuplicateEmail);
                }
                else
                {
                    throw ex;
                }
            }
            return(apiResult);
        }
        public async Task <IActionResult> CustomerDetails(int id)
        {
            HttpContext.Session.SetInt32("CurrentCustomer", id);

            var response = await WebApi.InitializeClient().GetAsync($"api/customers/{id}");

            var accounts = await WebApi.InitializeClient().GetAsync($"api/Accounts/AccountFromCustomer/{id}");

            if (!response.IsSuccessStatusCode || !accounts.IsSuccessStatusCode)
            {
                return(NotFound());
            }

            // Storing the response details recieved from web api.
            var result  = response.Content.ReadAsStringAsync().Result;
            var result2 = accounts.Content.ReadAsStringAsync().Result;

            // Deserializing the response recieved from web api and storing into a list.
            var customer     = JsonConvert.DeserializeObject <Customer>(result);
            var accountsList = JsonConvert.DeserializeObject <List <Account> >(result2);

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

            CustomerDetailsViewModel model = new CustomerDetailsViewModel
            {
                Customer = customer,
                Accounts = accountsList
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Details(string id)
        {
            var customer = _customerService.FindCustomerProfile(id);

            if (customer == null)
            {
                return(View("Error"));
            }

            var customerModel = new CustomerDetailsViewModel()
            {
                Id                = customer.Id,
                FirstName         = customer.FirstName,
                LastName          = customer.LastName,
                ImagePath         = Convert.ToBase64String(customer.Image),
                UserName          = customer.UserName,
                RegistrationdDate = customer.RegistrationdDate,
                CountPublishJobs  = customer.CountPublishJobs,
                CountReviews      = customer.QualityOfWorks.Count(),
            };

            if (customer.QualityOfWorks.Count() > 0)
            {
                customerModel.AvarageReviewMark = (int)customer.QualityOfWorks.Select(p => (int)p).Average();
            }

            int    countFeedbacksForPer     = customerModel.CountReviews == 0 ? 1 : customerModel.CountReviews;
            double percentPositiveFeedBacks = (double)customer.QualityOfWorks.Count(p => (int)p >= 3) * 100 / countFeedbacksForPer;

            customerModel.PercentPositiveReviews = (int)Math.Round(percentPositiveFeedBacks);

            return(View(customerModel));
        }
        public ActionResult UpdateAccount()
        {
            if (Session["CustomerId"] == null)
            {
                TempData["ReasontoLogin"] = "******";
                return(RedirectToAction("loginview", "login"));
            }
            int custID = Convert.ToInt32(Session["CustomerId"]);
            UpdateDetailsViewModel   viewModel  = new UpdateDetailsViewModel();
            CustomerDetailsViewModel viewModel2 = new CustomerDetailsViewModel();
            var tempCustomer = new HealthInsuranceDB().Customers.Find(custID);

            viewModel2.CustomerDetail    = tempCustomer;
            viewModel2.CityDetail        = new HealthInsuranceDB().Cities.Find(tempCustomer.CityID);
            viewModel2.StateDetail       = new HealthInsuranceDB().States.Find(tempCustomer.StateID);
            viewModel.FullCustomerDetail = viewModel2;
            var cities = new HealthInsuranceDB().Cities;

            viewModel.CityNames = cities.Select(c => new SelectListItem
            {
                Text  = c.CityName,
                Value = c.CityID.ToString()
            });
            var states = new HealthInsuranceDB().States;

            viewModel.StateNames = states.Select(s => new SelectListItem
            {
                Text  = s.StateName,
                Value = s.StateID.ToString()
            });
            ViewBag.date = tempCustomer.DateofBirth;
            return(View(viewModel));
        }
Exemplo n.º 5
0
        public IActionResult Details(int id)                            /* /Customers/Id */
        {
            try
            {
                CustomerDetailsViewModel model = new CustomerDetailsViewModel(Logger);
                bool isValid = model.Initialize(id);

                if (isValid)
                {
                    return(View(model));
                }

                Logger.LogError("Failure in CustomersController:Details. Directing user with AppError result", null);

                return(RedirectToAction("ApplicationError", "Abort"));
            }
            catch (Exception exception)
            {
                Debug.Assert(false, "Customer Details Initialization Exception");
                Debug.Assert(false, exception.Message);

                Logger.LogError(exception, "Exception in CustomersController:Details. Directing user with AppError result", null);

                return(RedirectToAction("ApplicationError", "Abort"));
            }
        }
        public IActionResult Search(CustomerDetailsViewModel model, int page = 1)
        {
            //var isAjax = Request.Headers["X-Requested-With"] == "XMLHttpRequest";

            //const int pageSize = 20;

            //var totalNumber = _context.Transactions.Where(a => a.AccountId == accountId).Count();

            //var transactions = _context.Transactions.Where(a => a.AccountId == accountId).Skip(pageSize * (page - 1)).Take(pageSize);

            //var model = new CustomerDetailsViewModel
            //{
            //    PageNumber = page,
            //    PageSize = pageSize,
            //    TotalNumberOfItems = totalNumber,
            //    CanShowMore = page * pageSize < totalNumber,
            //    Transactions = transactions.OrderBy(p => p.TransactionId).ToList()
            //};

            //if (isAjax)
            //{
            //    return PartialView("_TransactionRows", model);
            //}


            return(PartialView("_CustomerDetails"));
        }
Exemplo n.º 7
0
        public IActionResult Details(int id)
        {
            var viewModel = new CustomerDetailsViewModel();
            var customer  = _repository.GetAllAccountFromCustomer(id);

            viewModel.Customer = new CustomerDetailsViewModel.CustomerViewModel()
            {
                CustomerId           = customer.CustomerId,
                City                 = customer.City,
                Givenname            = customer.Givenname,
                Birthday             = customer.Birthday,
                Surname              = customer.Surname,
                Zipcode              = customer.Zipcode,
                NationalId           = customer.NationalId,
                Country              = customer.Country,
                CountryCode          = customer.CountryCode,
                Emailaddress         = customer.Emailaddress,
                Gender               = customer.Gender,
                Streetaddress        = customer.Streetaddress,
                Telephonecountrycode = customer.Telephonecountrycode,
                Telephonenumber      = customer.Telephonenumber
            };

            viewModel.Account = customer.Dispositions.Select(d => new CustomerDetailsViewModel.AccountViewModel
            {
                AccountId = d.Account.AccountId,
                Balance   = d.Account.Balance,
                Created   = d.Account.Created,
                Frequency = d.Account.Frequency
            }).ToList();

            viewModel.TotalCustAccount = viewModel.Account.Sum(a => a.Balance);

            return(View(viewModel));
        }
Exemplo n.º 8
0
        // GET: Customer/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            try
            {
                if (id == null)
                {
                    return(NotFound());
                }

                var customerViewModel = await _customerService.GetCustomerAsync(id.Value).ConfigureAwait(false);


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

                CustomerDetailsViewModel customerDetailsViewModel = CustomerDetailsMapper.Map(customerViewModel);


                IEnumerable <ProjectDto> Projects = await _projectService.GetProjectsByCustomerId(id.Value);


                customerDetailsViewModel.Projects = ProjectMapper.Map(Projects);

                return(View(customerDetailsViewModel));
            }
            catch (Exception)
            {
                ErrorViewModel model = new ErrorViewModel {
                    RequestId = "Kundens detajler kunne ikke vises"
                };
                return(View("Error", model));
            }
        }
        public CustomerDetailsViewModel GetCustomerDetails(int id)
        {
            Customer customerEntity = this.DbContext.Customers.Find(id);

            if (customerEntity.IsYoungDriver)
            {
                CustomerDetailsViewModel csvm = new CustomerDetailsViewModel()
                {
                    Name            = customerEntity.Name,
                    BoughtCarsCount = customerEntity.Sales.Count,
                    TotalSpentMoney = customerEntity.Sales
                                      .Sum(sale => sale.Car.Parts.Sum(c => c.Price) - (sale.Discount + 0.05) * sale.Car.Parts.Sum(c => c.Price))
                };

                return(csvm);
            }
            else
            {
                CustomerDetailsViewModel csvm = new CustomerDetailsViewModel()
                {
                    Name            = customerEntity.Name,
                    BoughtCarsCount = customerEntity.Sales.Count,
                    TotalSpentMoney = customerEntity.Sales
                                      .Sum(sale => sale.Car.Parts.Sum(c => c.Price) - sale.Discount * sale.Car.Parts.Sum(c => c.Price))
                };

                return(csvm);
            }
        }
Exemplo n.º 10
0
        public IActionResult CustomerDetails(string customerName)
        {
            CustomerDetailsViewModel customerDetailsViewModel = new CustomerDetailsViewModel {
                CountOfFinishedRepairTasks = this.repairTaskService
                                             .GetFinishedPerCustomerAsync(customerName)
                                             .GetAwaiter()
                                             .GetResult()
                                             .Count(),
                CountOfPendingRepairTasks = this.repairTaskService
                                            .GetPendingPerCustomerAsync(customerName)
                                            .GetAwaiter()
                                            .GetResult()
                                            .Count(),
                CountOfWorkedOnRepairTasks = this.repairTaskService
                                             .GetWorkedOnPerCustomerAsync(customerName)
                                             .GetAwaiter()
                                             .GetResult()
                                             .Count(),
                CustomerName = customerName,
                TotalRevenue = this.receiptService.GetTotalRevenuePerCustomer(customerName).HasValue
                ? this.receiptService.GetTotalRevenuePerCustomer(customerName).Value
                : 0
            };

            return(this.View(customerDetailsViewModel));
        }
Exemplo n.º 11
0
        public ActionResult Details(int Id)
        {
            var ViewModel = new CustomerDetailsViewModel()
            {
                Custom = customers_v.Find(x => x.Id.Equals(Id))
            };

            return(View(ViewModel));
        }
Exemplo n.º 12
0
        public ActionResult AddCustomer(FormCollection formCollection)
        {
            //var db = new CustomerRepositoryEntities1();
            var db = new MyDbContext();
            var c  = new Customer();
            var ca = new Address();


            c.CustomerName = formCollection["Name"];
            c.Email        = formCollection["Email"];
            c.dateUpdated  = DateTime.Now;
            c.updatedBy    = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            c.Dob          = Convert.ToDateTime(formCollection["Dob"]);

            string Line1      = formCollection["Line1"];
            string Line2      = formCollection["Line2"];
            string State      = formCollection["State"];
            string City       = formCollection["City"];
            string PostalCode = formCollection["PostalCode"];
            string Country    = formCollection["Country"];

            if (Request.Files.Count >= 1)
            {
                var file    = Request.Files[0];
                var imgByte = new Byte[file.ContentLength];
                file.InputStream.Read(imgByte, 0, file.ContentLength);
                var bas64String = Convert.ToBase64String(imgByte, 0, imgByte.Length);
                c.Photo = bas64String;
            }

            ca.Customer   = c;
            ca.Line1      = Line1;
            ca.Line2      = Line2;
            ca.State      = State;
            ca.City       = City;
            ca.PostalCode = PostalCode;
            ca.Country    = Country;


            db.Customers.Add(c);
            db.Addresses.Add(ca);

            db.SaveChanges();
            // get the last customer in the list.
            // now, we need to get the lo

            var cList = db.Customers.OrderBy(o => o.CustomerId).ToList();

            var customerDetailsViewmodel = new CustomerDetailsViewModel()
            {
                Customer  = cList,
                PageTitle = "Customer Details"
            };

            return(RedirectToAction("Index", customerDetailsViewmodel));
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Details(string id)
        {
            CustomerDetailsViewModel model = new CustomerDetailsViewModel();
            //Find user
            var user = await userManager.FindByIdAsync(id);

            mapper.Map(user, model);

            return(View(model));
        }
Exemplo n.º 14
0
 public CustomerDetailsView(CustomerDetailsViewModel vm)
 {
     InitializeComponent();
     this.DataContext = vm;
     //RegionContext.GetObservableContext(this).PropertyChanged += (s, e)
     //                                                            =>
     //                                                            DataContext.CurrentCustomer =
     //                                                            RegionContext.GetObservableContext(this).Value
     //                                                            as Customer;
 }
        public void Ctor_Always_CallsGetCustomer()
        {
            IUIDataProvider uiDataProviderMock = MockRepository.GenerateMock <IUIDataProvider>();
            const string    expectedID         = "EXPECTEDID";

            uiDataProviderMock.Expect(c => c.GetCustomer(expectedID)).Return(new Customer());

            CustomerDetailsViewModel target = new CustomerDetailsViewModel(uiDataProviderMock, expectedID);

            uiDataProviderMock.VerifyAllExpectations();
        }
Exemplo n.º 16
0
        public ActionResult Index()
        {
            MyStoreContext           _myStoreContext = new MyStoreContext();
            List <Customer>          customers       = _myStoreContext.Customer.OrderBy(a => a.LastName).ToList();
            CustomerDetailsViewModel customerModel   = new CustomerDetailsViewModel
            {
                Customers = customers
            };

            return(View(customerModel));
        }
Exemplo n.º 17
0
        public ActionResult CustomerDetails(CustomerDetailsViewModel model)
        {
            foreach (var item in model.Orders)
            {
                var order = _orderService.GetOrderById(item.Id);
                order.IsReady = item.IsReady;
                _orderService.UpdateOrder(order);
            }

            return(RedirectToAction("CustomerList"));
        }
Exemplo n.º 18
0
        public ActionResult Details(int id)
        {
            if (!this.service.CheckIfCustomerExists(id))
            {
                return(RedirectToAction("All"));
            }

            CustomerDetailsViewModel cdvm = this.service.GetCustomerDetails(id);

            return(View(cdvm));
        }
Exemplo n.º 19
0
        public void Ctor_Always_CallsGetCustomer()
        {
            // Arrange
            _uiDataProviderMock.Setup(uidp => uidp.GetCustomer(ExpectedID)).Returns(new Customer());

            // Act
            var target = new CustomerDetailsViewModel(_uiDataProviderMock.Object, ExpectedID);

            // Assert
            _uiDataProviderMock.VerifyAll();
        }
Exemplo n.º 20
0
        public ActionResult Details(int ID)
        {
            var customers = GetCustomers();

            var viewModel = new CustomerDetailsViewModel
            {
                Customers = customers,
                ID        = ID
            };

            return(View(viewModel));
        }
Exemplo n.º 21
0
        // GET: Customers/Details
        public ActionResult Details(int id)
        {
            var viewModel = new CustomerDetailsViewModel();

            viewModel.Customer = _context.Customers.Include(x => x.MembershipType).SingleOrDefault(x => x.Id == id);
            if (viewModel.Customer == null)
            {
                return(View("Error"));
            }

            return(View(viewModel));
        }
Exemplo n.º 22
0
        public RedirectToRouteResult Create(CustomerDetailsViewModel viewModel)
        {
            var command = new CreateCustomer
            {
                CustomerId = Guid.NewGuid(),
                FirstName  = viewModel.FirstName,
                LastName   = viewModel.LastName
            };

            bus.Send(command);
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 23
0
        public ActionResult CustomerDetails(int id)
        {
            var customer = new Customer {
                Id = id, Name = "Customer " + id
            };

            var viewModel = new CustomerDetailsViewModel
            {
                SelectedCustomer = customer
            };

            return(View(viewModel));
        }
Exemplo n.º 24
0
        public ActionResult Details(int id)
        {
            var customerDetailsViewModel = new CustomerDetailsViewModel();

            customerDetailsViewModel.Initialize(id);

            if (customerDetailsViewModel.Customer == null)
            {
                return(HttpNotFound());
            }

            return(View(customerDetailsViewModel));
        }
Exemplo n.º 25
0
        public static CustomerDetailsViewModel ToDetailsViewModel(this Customer source)
        {
            var destination = new CustomerDetailsViewModel();

            destination.Id            = source.Id;
            destination.Address       = source.Address;
            destination.ContactNumber = source.ContactNumber;
            destination.EmailAddress  = source.EmailAddress;
            destination.Name          = source.Name;
            destination.TaxExempted   = source.TaxExempted ? "Yes" : "No";

            return(destination);
        }
Exemplo n.º 26
0
        public ActionResult ShowCustomerDetails(int id)
        {
            var customer = _context.Customers.Include(c => c.MembershipType).SingleOrDefault(c => c.Id == id);

            var viewModel = new CustomerDetailsViewModel
            {
                Name           = customer.Name,
                MembershipType = customer.MembershipType.Name,
                Birthdate      = customer.Birthdate,
            };

            return(View(viewModel));
        }
Exemplo n.º 27
0
        public ActionResult OrderList()
        {
            var orders    = _orderService.GetOrdersByCustomer(CurrentUser.Id);
            var viewModel = new CustomerDetailsViewModel()
            {
                Orders = orders.Select(o => new OrderModel {
                    Id = o.Id, DeliveryDate = o.DeliveryDate, IsReady = o.IsReady
                }).ToList(),
                Customer = CurrentUser
            };

            return(View(viewModel));
        }
Exemplo n.º 28
0
        public ActionResult CustomerDetails(string userName)
        {
            var customer = _userService.Get(userName);
            var orders   = _orderService.GetOrdersByCustomer(customer.Entity.Id);
            var model    = new CustomerDetailsViewModel()
            {
                Orders = orders.Select(o => new OrderModel {
                    Id = o.Id, DeliveryDate = o.DeliveryDate, IsReady = o.IsReady
                }).ToList(),
                Customer = customer.Entity
            };

            return(View("~/Views/Admin/CustomerDetails.cshtml", model));
        }
Exemplo n.º 29
0
        public ActionResult Details(int id)
        {
            var customer = _context.Customers.SingleOrDefault(c => c.Id == id);
            CustomerDetailsViewModel customerDetailsViewModel = new CustomerDetailsViewModel
            {
                Customer = customer
            };

            if (customerDetailsViewModel.Customer != null)
            {
                return(View(customerDetailsViewModel));
            }
            return(HttpNotFound());
        }
Exemplo n.º 30
0
    public IActionResult ChangeName(CustomerDetailsViewModel customerDetailsViewModel)
    {
        var customer = _customerRepository.GetOne(customerDetailsViewModel.CustomerId);

        if (customer == null)
        {
            return(View(CustomerNotFoundPage, customerDetailsViewModel.CustomerId));
        }

        customer.UpdateName(customerDetailsViewModel.CustomerName);
        _customerRepository.UpdateOne(customer);

        return(RedirectToAction(CustomerDetailsPage, new { id = customer.Id }));
    }
Exemplo n.º 31
0
        public ActionResult Details(int customerId, int? page, string sortOrder = "")
        {
            var model = new CustomerDetailsViewModel();
            model.SortOrder = sortOrder;
            model.Customer = _customerRepository.Get(customerId);

            var orders = _orderRepository.GetAll().GetByCustomerId(customerId);
            var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1)

            model.SalesFNameSortParam = sortOrder == "SalesFName" ? "SalesFName Desc" : "SalesFName";
            model.SalesLNameSortParam = sortOrder == "SalesLName" ? "SalesLName Desc" : "SalesLName";
            model.DateOrderedSortParam = sortOrder == "DateOrdered" ? "DateOrdered Desc" : "DateOrdered";
            model.TotalSortParam = sortOrder == "Total" ? "Total Desc" : "Total";

            switch (sortOrder)
            {
                case "SalesFName":
                    orders = orders.SortBySalespersonFirstName(0);
                    break;
                case "SalesFName Desc":
                    orders = orders.SortBySalespersonFirstName(1);
                    break;
                case "SalesLName":
                    orders = orders.SortBySalespersonLastName(0);
                    break;
                case "SalesLName Desc":
                    orders = orders.SortBySalespersonLastName(1);
                    break;
                case "Total":
                    orders = orders.SortByGrandTotal(0);
                    break;
                case "Total Desc":
                    orders = orders.SortByGrandTotal(1);
                    break;
                case "DateOrdered Desc":
                    orders = orders.SortByDateOrdered(1);
                    break;
                default:
                    orders = orders.SortByDateOrdered(0);
                    break;
            }
            model.Orders = orders.ToPagedList(pageNumber, 10);
            return View(model);
        }
 public CustomerDetailsChangedMessage(CustomerDetailsViewModel customerDetails)
 {
     CustomerDetails = customerDetails;
 }