public IActionResult EditPhone(EditPhoneViewModel editedPhone)
        {
            if (ModelState.IsValid)
            {
                Phone phone = _employeeRepository.GetPhone(editedPhone.Id);
                phone.DisplayName  = editedPhone.DisplayName;
                phone.Model        = editedPhone.Model;
                phone.Price        = (decimal)editedPhone.Price;
                phone.OldPrice     = editedPhone.OldPrice;
                phone.Quantity     = editedPhone.Quantity;
                phone.Color        = editedPhone.Color;
                phone.Storage      = editedPhone.Storage;
                phone.Description  = editedPhone.Description;
                phone.Manufacturer = editedPhone.Manufacturer;

                if (editedPhone.Photo != null)
                {
                    if (editedPhone.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", editedPhone.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    phone.PhotoPath = ProcessUploadedFile(editedPhone);
                }
                Phone updatedPhone = _employeeRepository.UpdatePhone(phone);
                return(RedirectToAction("index", "home"));
            }
            return(View(editedPhone));
        }
示例#2
0
        public ActionResult EditPhone(EditPhoneViewModel model)
        {
            using (var db = Db4oEmbedded.OpenFile(path))
            {
                var telefon1 = db.Query<Telefon>(x => x.NumerTelefonu == model.OldPhone).First();
                var czyjestzajety = db.Query<Telefon>(x => x.NumerTelefonu == model.NumerTelefonu).Count() == 0;
                if (ModelState.IsValid && czyjestzajety)
                {
                    telefon1.CzyKomorkowy = model.CzyKomorkowy;
                    telefon1.NazwaOperatora = model.NazwaOperatora;
                    telefon1.NumerTelefonu = model.NumerTelefonu;

                    db.Store(telefon1);
                    db.Commit();
                    return RedirectToAction("Szczegoly", new
                    {
                        id = model.StudentId
                    });
                }
                if (!czyjestzajety)
                {
                    ModelState.AddModelError("NumerTelefonu", "taki nr telefonu już istnieje");
                }
            }
            return View(model);
        }
示例#3
0
        public async Task <IActionResult> EditPhoneNumber(CancellationToken cancellationToken)
        {
            var model = new EditPhoneViewModel();
            var user  = await _siteContext.AppDb.UserRepository.GetLoginUserByUserNameAsync(HttpContext.User.Identity.Name, cancellationToken);

            if (user == null)
            {
                _logger.LogError($"Username '{HttpContext.User.Identity.Name}' not found in repository");
                TempData.Put <ManageMessage>(nameof(ManageMessage), new ManageMessage {
                    AlertType = SiteAlertTagHelper.AlertType.Danger, MessageId = MessageId.ChangePhoneFailure
                });
                ModelState.AddModelError(string.Empty, _localizer["Primary phone number not found"]);
                return(PartialView(ViewNames.Manage._EditPhoneModalPartial, model));
            }

            model.PhoneNumber = _phoneNumberService.Format(user.PhoneNumber, _regionInfo.TwoLetterISORegionName);
            return(PartialView(ViewNames.Manage._EditPhoneModalPartial, model));
        }
        public IActionResult EditPhone(int id)
        {
            Phone phone = _employeeRepository.GetPhone(id);
            EditPhoneViewModel editPhoneViewModel = new EditPhoneViewModel
            {
                Id                = phone.Id,
                DisplayName       = phone.DisplayName,
                Model             = phone.Model,
                Price             = phone.Price,
                OldPrice          = phone.OldPrice,
                Quantity          = phone.Quantity,
                Color             = phone.Color,
                Storage           = phone.Storage,
                Description       = phone.Description,
                Manufacturer      = phone.Manufacturer,
                ExistingPhotoPath = phone.PhotoPath
            };

            return(View(editPhoneViewModel));
        }
 public EditPhonePopup()
 {
     InitializeComponent();
     _viewModel     = new EditPhoneViewModel(Navigation);
     BindingContext = _viewModel;
 }
示例#6
0
 private EditPhoneViewModel GetEditModel(Phone phone)
 {
     ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", phone.Id);
     ViewData["Companies"]  = new SelectList(_context.Companies, "Id", "Name", phone.Id);
     return(EditPhoneViewModel.Cast(phone));
 }
示例#7
0
        public async Task <IActionResult> EditPhoneNumber(EditPhoneViewModel model, CancellationToken cancellationToken)
        {
            UserEntity userEntity = null;

            async Task <IActionResult> Save()
            {
                // Save in unformatted, international format
                userEntity.PhoneNumber = _phoneNumberService.FormatForStorage(model.PhoneNumber, _regionInfo.TwoLetterISORegionName);

                try
                {
                    await _siteContext.AppDb.GenericRepository.SaveEntityAsync(userEntity, false, false, cancellationToken);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Save user name '{userEntity.UserName}' failed", e);
                    TempData.Put <ManageMessage>(nameof(ManageMessage), new ManageMessage {
                        AlertType = SiteAlertTagHelper.AlertType.Danger, MessageId = MessageId.ChangePhoneFailure
                    });
                    return(JsonAjaxRedirectForModal(Url.Action(nameof(Index), nameof(Manage), new { Organization = _siteContext.UrlSegmentValue })));
                }

                TempData.Put <ManageMessage>(nameof(ManageMessage), new ManageMessage {
                    AlertType = SiteAlertTagHelper.AlertType.Success, MessageId = MessageId.ChangePhoneSuccess
                });
                return(JsonAjaxRedirectForModal(Url.Action(nameof(Index), nameof(Manage), new { Organization = _siteContext.UrlSegmentValue })));
            }

            if (!ModelState.IsValid)
            {
                return(PartialView(ViewNames.Manage._EditPhoneModalPartial, model));
            }
            ModelState.Clear();

            userEntity = await _siteContext.AppDb.UserRepository.GetLoginUserByUserNameAsync(User.Identity.Name, cancellationToken);

            if (userEntity == null)
            {
                TempData.Put <ManageMessage>(nameof(ManageMessage), new ManageMessage {
                    AlertType = SiteAlertTagHelper.AlertType.Danger, MessageId = MessageId.ChangePhoneFailure
                });
                return(JsonAjaxRedirectForModal(Url.Action(nameof(Index), nameof(Manage), new { Organization = _siteContext.UrlSegmentValue })));
            }

            // Remove the phone number
            if (string.IsNullOrEmpty(model.PhoneNumber))
            {
                model.PhoneNumber = string.Empty;
                return(await Save());
            }

            if (!string.IsNullOrWhiteSpace(model.PhoneNumber))
            {
                var validator = new TournamentManager.ModelValidators.PhoneNumberValidator(model.PhoneNumber, (_phoneNumberService, _regionInfo));
                await validator.CheckAsync(cancellationToken);

                validator.GetFailedFacts().ForEach(f => ModelState.AddModelError(nameof(model.PhoneNumber), f.Message));
            }

            if (!ModelState.IsValid)
            {
                return(PartialView(ViewNames.Manage._EditPhoneModalPartial, model));
            }

            if (_phoneNumberService.IsMatch(userEntity.PhoneNumber, model.PhoneNumber, _regionInfo.TwoLetterISORegionName))
            {
                _logger.LogInformation($"Current and new primary phone number are equal ('{userEntity.PhoneNumber}').");
                ModelState.AddModelError(nameof(EditPhoneViewModel.PhoneNumber), _localizer["Current and new primary phone number must be different"]);
                return(PartialView(ViewNames.Manage._EditPhoneModalPartial, model));
            }

            if (_phoneNumberService.IsMatch(userEntity.PhoneNumber2, model.PhoneNumber, _regionInfo.TwoLetterISORegionName))
            {
                _logger.LogInformation($"Primary and additional phone number are equal ('{userEntity.PhoneNumber}').");
                ModelState.AddModelError(nameof(EditPhone2ViewModel.PhoneNumber2), _localizer["'{0}' and '{1}' must be different", _metaData.GetDisplayName <EditPhoneViewModel>(nameof(EditPhoneViewModel.PhoneNumber)), _metaData.GetDisplayName <EditPhone2ViewModel>(nameof(EditPhone2ViewModel.PhoneNumber2))]);
                return(PartialView(ViewNames.Manage._EditPhoneModalPartial, model));
            }

            return(await Save());
        }