public ActionResult UploadPicture()
        {
            string currentUserId = User.Identity.GetUserId();
            CustomerProfileViewModel customerProfileVm = this._service.GetCurrentUserProfile(currentUserId);

            HttpPostedFileBase file = this.Request.Files["picture"];

            if (file == null)
            {
                ModelState.AddModelError("", "Please browse for a valid image file, and then click Upload.");
                return(this.View("UserProfile", customerProfileVm));
            }

            if (file.ContentLength > 2097152)
            {
                ModelState.AddModelError("", "Image size should be less than 2mb.");
                return(this.View("UserProfile", customerProfileVm));
            }

            string fileName = Path.GetFileName(file.FileName);

            if (!fileName.ToLower().EndsWith(".jpg") && !fileName.ToLower().EndsWith(".png") && !fileName.ToLower().EndsWith(".jpeg"))
            {
                ModelState.AddModelError("", "Invalid picture format!");
                return(this.View("UserProfile", customerProfileVm));
            }

            MemoryStream memstr = new MemoryStream();

            file.InputStream.CopyTo(memstr);
            byte[] imageData = memstr.ToArray();

            this._service.UploadUserProfilePicture(currentUserId, fileName, imageData);
            return(RedirectToAction("UserProfile", "Customers"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(CustomerProfileViewModel vm)
        {
            var user = await _userManager.GetUserAsync(User);

            //check if data is valid
            if (ModelState.IsValid)
            {
                Customer cust = new Customer()
                {
                    FirstName = vm.FirstName,
                    LastName  = vm.LastName,
                    //user.Email = vm.Email,
                    DOB         = vm.DOB.Date,
                    PhoneNumber = vm.PhoneNumber,
                    UserID      = user.Id
                };

                //call service
                _customerService.Create(cust);

                //go back to home
                return(RedirectToAction("Index", "Home"));
            }
            //if invalid
            return(View());
        }
        public ActionResult Profile()
        {
            string customerName         = this.User.Identity.Name;
            CustomerProfileViewModel vm = this.service.GetProfileVm(customerName);

            return(this.View(vm));
        }
        public async Task <IActionResult> UpdateCustomerProfileAsync(
            [FromBody, SwaggerParameter("Model containing the details of the User to update", Required = true)] CustomerProfileViewModel users)
        {
            int result = await _userBusiness.UpdateCustomerProfileAsync(users);

            return(commonMethods.GetResultMessages(result, MethodType.Update));
        }
Ejemplo n.º 5
0
        public IActionResult EditNameProfile(long id)
        {
            //check to see if customer with specified id exists
            var customerToFind = _db.Customers.FirstOrDefault(x => x.CustomerId == id);

            if (customerToFind == null)
            {
                return(RedirectToAction("List"));
            }

            //if it does send all data of customer to new model to be displayed
            var profile = new CustomerProfileViewModel
            {
                Given     = customerToFind.FirstName,
                Surname   = customerToFind.LastName,
                Creation  = customerToFind.DateCreated,
                Phones    = _db.PhoneNumbers.Where(p => p.CustomerId == id).ToList(),
                Emails    = _db.Emails.Where(e => e.CustomerId == id).ToList(),
                Addresses = _db.MailingAddresses.Where(x => x.CustomerId == id).ToList(),
                CusId     = customerToFind.CustomerId
            };

            if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
            {
                return(PartialView(profile));
            }

            return(View(profile));
        }
Ejemplo n.º 6
0
        public IActionResult EditNameProfile(long id, CustomerProfileViewModel edited)
        {
            //check to see if customer with specified id exists
            var customerToFind = _db.Customers.FirstOrDefault(x => x.CustomerId == id);

            if (customerToFind == null)
            {
                return(RedirectToAction("List"));
            }

            //assign the rest of the parts of the model with existing data so model can be resent
            edited.Creation  = customerToFind.DateCreated;
            edited.CusId     = customerToFind.CustomerId;
            edited.Phones    = _db.PhoneNumbers.Where(p => p.CustomerId == id).ToList();
            edited.Emails    = _db.Emails.Where(e => e.CustomerId == id).ToList();
            edited.Addresses = _db.MailingAddresses.Where(x => x.CustomerId == id).ToList();

            //make sure model is valid
            if (!ModelState.IsValid)
            {
                return(View(edited));
            }

            customerToFind.FirstName = edited.Given;
            customerToFind.LastName  = edited.Surname;

            _db.SaveChanges();

            return(RedirectToAction("profile", "customer", new { id = customerToFind.CustomerId }));
        }
        public async Task <IActionResult> EditCustomerProfile(CustomerProfileViewModel editCustomerProfile)
        {
            var username = User.Identity.Name;
            var user     = await _userManager.FindByNameAsync(username);

            var customer = await _customerService.GetCustomerByUserId(user.Id);

            var profile = _mapper.Map <CustomerProfileDto>(editCustomerProfile);

            if (editCustomerProfile.ImageFile != null)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(editCustomerProfile.ImageFile.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)editCustomerProfile.ImageFile.Length);
                }
                profile.Image = imageData;
            }
            else
            {
                profile.Image = customer.Image;
            }
            await _customerService.Edit(profile);

            return(RedirectToAction("CustomerProfile"));
        }
Ejemplo n.º 8
0
        // GET: Customer/Login : Logs in by ID
        public ActionResult Login()
        {
            var viewModel = new CustomerProfileViewModel();

            TempData.Remove("LoggedCustomer");
            return(View(viewModel));
        }
Ejemplo n.º 9
0
        public ActionResult Index()
        {
            var customerFormViewModel = new CustomerProfileViewModel();

            customerFormViewModel.Customer = _customer;

            return(View(customerFormViewModel));
        }
Ejemplo n.º 10
0
        public ActionResult DeleteConfirmed(int id)
        {
            CustomerProfileViewModel customerProfileViewModel = db.CustomerProfileViewModels.Find(id);

            db.CustomerProfileViewModels.Remove(customerProfileViewModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 11
0
        // GET: CustomersProfile
        public ActionResult _CustomersProfile()
        {
            context = new ApplicationDbContext();
            var model  = new CustomerProfileViewModel();
            var states = GetAllStates();

            model.StatesList = GetSelectListItems(states);
            return(PartialView(model));
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "CustomerProfileViewModelId,CompanyId,Firstname,Lastname,Email,Phonenumber,Address,City,PostalNr,Nationality,DateCreated,CompanyName")] CustomerProfileViewModel customerProfileViewModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerProfileViewModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customerProfileViewModel));
 }
Ejemplo n.º 13
0
        public IActionResult Create()
        {
            var user = User.Identity.Name;
            CustomerProfileViewModel cust = new CustomerProfileViewModel
            {
                Email = user
            };

            return(View(cust));
        }
Ejemplo n.º 14
0
        public ActionResult Edit(Customer customer)
        {
            int id = customer.Id;

            Customers.Update(customer.Id, customer);
            CustomerProfileViewModel ProfileCustomer = new CustomerProfileViewModel(customer,
                                                                                    Appointments.GetByCustomerId(id), Orders.GetByCustomerId(id));

            return(View("Details", ProfileCustomer));
        }
        public PartialViewResult GetPartialProfile()
        {
            string                   uid   = User.Identity.GetUserId();
            ApplicationUser          user  = context.Users.SingleOrDefault(x => x.Id == uid);
            CustomerProfileViewModel model = new CustomerProfileViewModel();

            model.Username = user.UserName;

            Session["customerpage"] = "Profile";
            return(PartialView("_CustomerProfile", model));
        }
Ejemplo n.º 16
0
        public ActionResult ProfileEdit()
        {
            var userId = User.Identity.GetUserId().ToString();
            var user   = _context.Users.FirstOrDefault(u => u.Id == userId);

            var customerProfilViewModel = new CustomerProfileViewModel();

            customerProfilViewModel.Customer = _customer;
            customerProfilViewModel.Email    = user.Email;

            return(View("ProfileForm", customerProfilViewModel));
        }
Ejemplo n.º 17
0
 public ActionResult Create(CustomerProfileViewModel model)
 {
     if (ModelState.IsValid)
     {
         var created = _customerProfileRepository.CreateCustomerProfile(model);
         if (string.IsNullOrEmpty(created))
         {
             return(RedirectToAction("Index"));
         }
         ViewBag.ErrorMessage = created;
     }
     return(View());
 }
        public async Task <IActionResult> UpdateCustomerProfile([FromQuery] string email)
        {
            var message = TempData["message"];

            email = HttpContext.Session.GetString("username");
            CustomerProfiles customerProfiles = await _customerProfileService.CustomerProfile(email);

            CustomerProfileViewModel customerProfileViewModel = new CustomerProfileViewModel {
                customerDto = customerProfiles, Message = message?.ToString() ?? string.Empty
            };

            return(View("UpdateCustomerProfile", customerProfileViewModel));
        }
Ejemplo n.º 19
0
        public CustomerProfileViewModel GetProfileVm(string customerName)
        {
            ApplicationUser currUser     = this.Context.Users.FirstOrDefault(user => user.UserName == customerName);
            Customer        currCustomer = this.Context.Customers.FirstOrDefault(c => c.User.Id == currUser.Id);
            var             vacations    =
                Mapper.Map <IEnumerable <Vacation>, IEnumerable <CustomerVacationViewModel> >(currCustomer.Vacations);
            CustomerProfileViewModel vm = Mapper.Map <Customer, CustomerProfileViewModel>(currCustomer);

            vm.Vacations = vacations;


            return(vm);
        }
        public CustomerProfileViewModel GetCustomerProfileDetails(int id)
        {
            string url      = $"api/Customers/{id}";
            var    response = _serviceClient.GetResponse(url);

            if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(null);
            }
            CustomerProfileViewModel custProfile = response.Content.ReadAsAsync <CustomerProfileViewModel>().Result;

            return(custProfile);
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Profile()
        {
            var User = await GetCurrentUserAsync();

            var model = new CustomerProfileViewModel();

            model.CustomerUser = User;

            model.estimates = await context.Estimate.ToListAsync();

            model.messages = await context.Message.ToListAsync();

            return(View(model));
        }
Ejemplo n.º 22
0
        // GET: CustomerProfile/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerProfileViewModel customerProfileViewModel = db.CustomerProfileViewModels.Find(id);

            if (customerProfileViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(customerProfileViewModel));
        }
        public ActionResult UserProfile()
        {
            var currentUserId = this.User.Identity.GetUserId();

            try
            {
                CustomerProfileViewModel customerProfileVm = this._service.GetCurrentUserProfile(currentUserId);
                return(View(customerProfileVm));
            }
            catch (Exception)
            {
                throw new ArgumentException();
            }
        }
Ejemplo n.º 24
0
        public IActionResult Profile(long id)
        {
            //check to see if customer with specified id exists
            var customerToFind = _db.Customers.FirstOrDefault(x => x.CustomerId == id);

            if (customerToFind == null)
            {
                return(RedirectToAction("List"));
            }

            //grab all the work orders associated with the customer
            var workOrders = _db.WorkOrders.Where(o => o.CustomerId == id)
                             .OrderByDescending(o => o.WorkOrderNumber).ToList();

            var listOrders = new List <WorkOrderListViewModel>();

            foreach (var order in workOrders)
            {
                var listOrder = new WorkOrderListViewModel
                {
                    OrderNumber = order.WorkOrderNumber,
                    OrderStatus = order.Status,
                    StatusDate  = order.StatusLastUpdatedAt,
                    DeviceCount = _db.Devices.Count(d => d.WorkOrderNumber == order.WorkOrderNumber)
                };
                listOrders.Add(listOrder);
            }

            //if exists send all data of customer to new model to be displayed
            var profile = new CustomerProfileViewModel
            {
                Given      = customerToFind.FirstName,
                Surname    = customerToFind.LastName,
                Creation   = customerToFind.DateCreated,
                Phones     = _db.PhoneNumbers.Where(p => p.CustomerId == id).ToList(),
                Emails     = _db.Emails.Where(e => e.CustomerId == id).ToList(),
                Addresses  = _db.MailingAddresses.Where(x => x.CustomerId == id).ToList(),
                CusId      = customerToFind.CustomerId,
                WorkOrders = listOrders
            };

            if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
            {
                return(PartialView(profile));
            }

            return(View(profile));
        }
        public async Task <IActionResult> InsertCustomerProfile(CustomerProfileViewModel customerProfileViewModel)
        {
            CustomerProfiles customer = customerProfileViewModel.customerDto;

            customer.CustomerType    = "Normal";
            customer.CustomerActive  = true;
            customer.CreatedBy       = "System";
            customer.CreatedTime     = DateTime.Now;
            customer.LastUpdatedBy   = "System";
            customer.LastUpdatedTime = DateTime.Now;
            customer.VersionNo       = 1;
            customer.IsDeleted       = false;
            string result = await _customerProfileService.CreateCustomer(customer);

            return(View("SuccessCustomerClick", customerProfileViewModel));
        }
Ejemplo n.º 26
0
        public async Task UpdateCustomerProfileAsync(CustomerProfileViewModel viewModel, string userId)
        {
            var dataModel = _mapper.Map <CustomerProfile>(viewModel);

            dataModel.Id = userId;
            if (await context.CustomerProfiles.AnyAsync(x => x.Id == dataModel.Id))
            {
                context.CustomerProfiles.Attach(dataModel);
                context.Entry <CustomerProfile>(dataModel).State = EntityState.Modified;
            }
            else
            {
                context.CustomerProfiles.Add(dataModel);
            }
            await context.SaveChangesAsync();
        }
Ejemplo n.º 27
0
        public async Task <ActionResult> UpdateProfile(CustomerProfileViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userId = User.Identity.GetUserId();

            if (userId != null)
            {
                await _customerManager.UpdateCustomerProfileAsync(model, userId);

                return(RedirectToAction("Index", new { Message = ManageMessage.UpdateProfileSuccess }));
            }
            return(RedirectToAction("Index", new { Message = ManageMessage.Error }));
        }
Ejemplo n.º 28
0
        public IActionResult Profile()
        {
            string   userId   = _userManager.GetUserId(User);
            Customer customer = _customerService.GetSingle(c => c.UserID == userId);
            var      user     = User.Identity.Name;

            CustomerProfileViewModel vm = new CustomerProfileViewModel
            {
                FirstName   = customer.FirstName,
                LastName    = customer.LastName,
                DOB         = customer.DOB,
                PhoneNumber = customer.PhoneNumber,
                Email       = user
            };

            return(View(vm));
        }
Ejemplo n.º 29
0
        public ActionResult ProfileSave(CustomerProfileViewModel customerFormViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("CustomerForm", customerFormViewModel));
            }

            var customerInDB = _context.Customers.Single <Customer>(c => c.Id == customerFormViewModel.Customer.Id);

            customerInDB.FirstName   = customerFormViewModel.Customer.FirstName;
            customerInDB.LastName    = customerFormViewModel.Customer.LastName;
            customerInDB.PhoneNumber = customerFormViewModel.Customer.PhoneNumber;

            _context.SaveChanges();

            return(RedirectToAction("ProfileEdit", "Customer"));
        }
Ejemplo n.º 30
0
 public ActionResult Update(CustomerProfileViewModel model)
 {
     if (ModelState.IsValid)
     {
         (var customerProfile, string errorMsg) = _customerProfileRepository.UpdateCustomerProfile(model);
         if (string.IsNullOrEmpty(errorMsg))
         {
             return(RedirectToAction("Index"));
         }
         TempData["ErrorMessage"] = errorMsg;
     }
     else
     {
         TempData["ErrorMessage"] = "Error while updating customer profile.";
     }
     TempData.Keep("ErrorMessage");
     return(RedirectToAction($"Edit/{model.Id}"));
 }