Beispiel #1
0
        public ActionResult Edit(EditProviderViewModel model)
        {
            var currProvider = providerRepo.ResultTable.Where(i => i.Id == model.ProviderId).First();
            var currAddress  = addressRepo.ResultTable.Where(i => i.Id == currProvider.AddressId).First();

            currAddress.Address1 = model.Address1;
            currAddress.Address2 = model.Address2;
            currAddress.City     = model.City;
            currAddress.State    = model.State;
            if (model.Zip != "")
            {
                currAddress.Zip = model.Zip;
            }


            addressRepo.Save(currAddress);

            currProvider.OrganizationName = model.OrganizationName;
            currProvider.Description      = model.Description;
            currProvider.UserId           = model.UserId;
            if (model.ChangeUser != null)
            {
                currProvider.UserId = model.ChangeUser;
            }
            providerRepo.Save(currProvider);

            return(RedirectToAction("Details", new { id = model.ProviderId }));
        }
Beispiel #2
0
        public async Task <IActionResult> EditProvider()
        {
            bool IsUserAuthenticated = HttpContext.User.Identity.IsAuthenticated;

            if (IsUserAuthenticated)
            {
                string userName = HttpContext.User.Identity.Name;

                ApplicationUser user = await _userManagerService.FindByNameAsync(userName);

                Provider provider = _providerRepo.GetSingle(p => p.UserId == user.Id);

                EditProviderViewModel vm = new EditProviderViewModel
                {
                    Username    = user.UserName,
                    Phone       = user.PhoneNumber,
                    Email       = user.Email,
                    DisplayName = provider.DisplayName,
                    ABN         = provider.ABN
                };

                return(View(vm));
            }
            return(Content("Must be logged in!"));
        }
Beispiel #3
0
        private EditProviderViewModel GetModelWithProviderId(int providerId)
        {
            var currProvider       = providerRepo.ResultTable.Where(i => i.Id == providerId).First();
            var currAddress        = addressRepo.ResultTable.Where(i => i.Id == currProvider.AddressId).First();
            var currLocations      = currProvider.Locations;
            var locationSelectList = GetLocationList(currLocations.ToList());
            var otherLocations     = GetOtherLocations(currLocations.ToList());
            var userSelectList     = new List <SelectListItem>();
            var users = userRepo.ResultTable.ToList();

            userSelectList = GetUserList(users);
            var model = new EditProviderViewModel();

            model.Address1         = currAddress.Address1;
            model.Address2         = currAddress.Address2;
            model.City             = currAddress.City;
            model.State            = currAddress.State;
            model.Zip              = currAddress.Zip;
            model.OrganizationName = currProvider.OrganizationName;
            model.Description      = currProvider.Description;
            model.AddressId        = currAddress.Id;
            model.UserId           = currProvider.UserId;
            model.ProviderId       = providerId;
            if (currProvider.UserId != null)
            {
                model.CurrentRepresentative = userRepo.ResultTable.Where(x => x.Id == currProvider.UserId).First();
            }

            model.ProviderRep = new SelectList(userSelectList.OrderBy(x => x.Text)
                                               , "Value", "Text", model.UserId);

            return(model);
        }
Beispiel #4
0
        // GET: ServiceProvider/Edit/5
        public ActionResult Edit(int id)
        {
            var currProvider   = providerRepo.ResultTable.Where(x => x.Id == id).First();
            var currUser       = userRepo.ResultTable.Where(x => x.Id == currProvider.UserId).First();
            var userList       = userRepo.ResultTable.ToList();
            var userSelectList = GetUserList(userList);
            var model          = new EditProviderViewModel()
            {
                ProviderId       = id,
                OrganizationName = currProvider.OrganizationName,
                Address1         = currProvider.Address.Address1,
                Address2         = currProvider.Address.Address2,
                City             = currProvider.Address.City,
                State            = currProvider.Address.State,
                Zip                   = currProvider.Address.Zip,
                Description           = currProvider.Description,
                CurrentRepresentative = currUser,
                UserId                = currUser.Id
            };

            model.ProviderRep = new SelectList(userSelectList.OrderBy(x => x.Text)
                                               , "Value", "Text", model.UserId);



            return(View(model));
        }
        public ActionResult Edit(int?id)
        {
            _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Provider/Edit");

            try
            {
                ProviderDTO providerDto = _providerService.GetProvider(id);

                if (providerDto == null)
                {
                    throw new ValidationException(_sharedLocalizer["ProviderNoFind"], "");
                }


                var provider = new EditProviderViewModel()
                {
                    Id           = providerDto.Id,
                    Email        = providerDto.Email,
                    Info         = providerDto.Info,
                    IsActive     = providerDto.IsActive,
                    IsFavorite   = providerDto.IsFavorite,
                    Name         = providerDto.Name,
                    Path         = _path + providerDto.Path,
                    TimeWorkTo   = providerDto.TimeWorkTo,
                    TimeWorkWith = providerDto.TimeWorkWith,
                    WorkingDays  = providerDto.WorkingDays
                };

                return(View(provider));
            }
            catch (ValidationException ex)
            {
                return(Content(ex.Message));
            }
        }
Beispiel #6
0
        public async Task <IActionResult> EditProvider(EditProviderViewModel vm)
        {
            if (ModelState.IsValid)
            {
                //return Content("So far so good.");

                /*
                 * var user = new ApplicationUser
                 * {
                 *  UserName = vm.Username,
                 *  PhoneNumber = vm.Phone,
                 *  Email = vm.Email
                 * };
                 */

                //save to db
                //you don't want to do it in your main thread
                //this method needs to be an async method
                ApplicationUser specificUser = await _userManagerService.FindByNameAsync(vm.Username);

                specificUser.PhoneNumber = vm.Phone;
                specificUser.Email       = vm.Email;

                IdentityResult result = await _userManagerService.UpdateAsync(specificUser);

                if (result.Succeeded)
                {
                    /*
                     * Provider updatedProvier = new Provider
                     * {
                     *  UserId = specificUser.Id,
                     *  DisplayName = vm.DisplayName,
                     *  ABN = vm.ABN
                     * };
                     */

                    Provider updatedProvider = _providerRepo.GetSingle(p => p.UserId == specificUser.Id);
                    updatedProvider.DisplayName = vm.DisplayName;
                    updatedProvider.ABN         = vm.ABN;

                    _providerRepo.Update(updatedProvider);

                    return(RedirectToAction("Index", "Packages"));
                }
                else
                {
                    foreach (var err in result.Errors)
                    {
                        //ModelState.AddModelError("" , "error");
                        ModelState.AddModelError("", err.Description);
                    }
                }
            }

            return(View(vm));
        }
        public async Task <ActionResult> Edit(IFormFile uploadedFile, [FromForm] EditProviderViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    ProviderDTO providerDto = null;
                    string      path        = null;

                    // сохранение картинки
                    if (uploadedFile != null)
                    {
                        path = uploadedFile.FileName;
                        // сохраняем файл в папку files/provider/ в каталоге wwwroot
                        using (var fileStream = new FileStream(_appEnvironment.WebRootPath + _path + path, FileMode.Create))
                        {
                            await uploadedFile.CopyToAsync(fileStream);

                            _logger.LogInformation($@"{DateTime.Now.ToString()}: Save image {path} in {_path}");
                        }
                    }
                    else
                    {
                        path = model.Path;
                    }

                    providerDto = new ProviderDTO
                    {
                        Id           = model.Id,
                        Email        = model.Email,
                        Info         = model.Info,
                        IsActive     = model.IsActive,
                        IsFavorite   = model.IsFavorite,
                        Name         = model.Name,
                        Path         = path.Replace(_path, ""),
                        TimeWorkTo   = model.TimeWorkTo,
                        TimeWorkWith = model.TimeWorkWith,
                        WorkingDays  = model.WorkingDays
                    };

                    _providerService.EditProvider(providerDto);

                    string currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                    _logger.LogInformation($"{DateTime.Now.ToString()}: User {currentUserId} edited provider {model.Id}");

                    return(RedirectToAction("Index"));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError(ex.Property, ex.Message);
                    _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
                }
            }
            return(View(model));
        }
Beispiel #8
0
        public async Task <IActionResult> EditProvider(int id)
        {
            var groupItems = await GetGroupItems();

            var repo     = new ServiceProviderRepository();
            var provider = await repo.GetByIdAsync(id);

            var model = new EditProviderViewModel
            {
                Provider   = provider,
                GroupItems = groupItems,
            };

            repo.Dispose();

            return(View(model));
        }
Beispiel #9
0
        public async Task <IActionResult> EditProvider(EditProviderViewModel model, int serviceId)
        {
            var groupItems = await GetGroupItems();

            model.GroupItems = groupItems;

            if (model.Provider.Id == 0)
            {
                model.Provider.ServiceId = serviceId;
                using (var repo1 = new ServiceProviderRepository())
                {
                    await repo1.AddAsync(model.Provider);

                    return(View(model));
                }
            }

            var repo = new ServiceProviderRepository();
            await repo.UpdateAsync(model.Provider);

            return(View(model));
        }
Beispiel #10
0
        public ActionResult Create(EditProviderViewModel model)
        {
            var newProvider = new ServiceProvider();
            var newAddress  = new Address();

            newAddress.Address1 = model.Address1;
            newAddress.Address2 = model.Address2;
            newAddress.City     = model.City;
            newAddress.State    = model.State;
            newAddress.Zip      = model.Zip;

            newAddress = addressRepo.Save(newAddress);

            newProvider.AddressId          = newAddress.Id;
            newProvider.OrganizationName   = model.OrganizationName;
            newProvider.Description        = model.Description;
            newProvider.OrganizationTypeId = 5;
            newProvider.UserId             = model.UserId;
            newProvider.Locations          = GetSelectedLocations(model.SelectedLocations);
            providerRepo.Save(newProvider);

            return(RedirectToAction("Details", new { id = newProvider.Id }));
        }
        public ActionResult Edit(EditProviderViewModel model)
        {
            if (model.Bill.IBAN != null)
            {
                if (!StaticFunctions.ValidateBankAccount(model.Bill.IBAN))
                {
                    this.ModelState.AddModelError("", BillTr.IBANIsNotCorrect);
                }
            }


            if (!ModelState.IsValid || model.SeletedOrganisationId == 0 || model.Bill.SelectedCurrency == 0)
            {
                if (model.SeletedOrganisationId == 0 || model.Bill.SelectedCurrency == 0)
                {
                    this.ModelState.AddModelError("", Common.Error);
                }
                if (!this.IsMegaAdmin())
                {
                    model.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());
                    model.Bill.Currency         = this.currencyService.GetAll()
                                                  .Where(x => x.OrganisationId == this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                                                  .ToList()
                                                  .ConvertAll(x =>
                                                              new CurrencyViewModel
                    {
                        Code = x.Code,
                        Id   = x.Id
                    })
                                                  .ToList();
                }
                else
                {
                    model.SeletedOrganisationId = model.SeletedOrganisationId;

                    model.Bill.Currency = this.currencyService.GetAll()
                                          .Where(x => x.OrganisationId == model.SeletedOrganisationId)
                                          .ToList()
                                          .ConvertAll(x =>
                                                      new CurrencyViewModel
                    {
                        Code = x.Code,
                        Id   = x.Id
                    })
                                          .ToList();
                }

                return(View(model));
            }

            var userORg = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());

            if (this.IsMegaAdmin())
            {
                userORg = model.SeletedOrganisationId;
            }
            //Check is there another provider with the same email
            if (this.providerService.ExistUpdate(model.Email, model.Id, userORg))
            {
                this.ModelState.AddModelError("", ProviderTr.ExistSameEmail);

                model.Bill.Currency = this.currencyService.GetAll().ToList()
                                      .ConvertAll(x =>
                                                  new CurrencyViewModel
                {
                    Code = x.Code,
                    Id   = x.Id,
                    // IsBase = x.IsBase
                })
                                      .ToList();

                return(View(model));
            }

            var provider = new Provider
            {
                Id      = model.Id,
                Status  = model.Status,
                Phone   = model.Phone,
                Name    = model.Name,
                Email   = model.Email,
                Bulstat = model.Bulstat,
                Address = model.Address
            };

            this.providerService.Update(provider);

            this.billService.Update(new Bill
            {
                IBAN       = model.Bill.IBAN,
                Id         = model.Bill.Id,
                CurrencyId = model.Bill.SelectedCurrency
            });
            return(Redirect("/HelpModule/Provider/GetAll"));
        }
        public ActionResult Edit(int id)
        {
            var provider = this.providerService.GetById(id);

            //Verify if asset is from user organisation
            if (!this.IsMegaAdmin())
            {
                if (provider.OrganisationId != this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                {
                    return(Redirect("/Home/NotAuthorized"));
                }
            }


            var viewModel = new EditProviderViewModel
            {
                Email   = provider.Email,
                Id      = provider.Id,
                Name    = provider.Name,
                Phone   = provider.Phone,
                Status  = provider.Status,
                Bulstat = provider.Bulstat,
                Address = provider.Address
            };

            viewModel.Bill = new AddBillProviderViewModel();
            viewModel.Bill.SelectedCurrency = provider.Bill.CurrencyId;
            viewModel.Bill.Id   = provider.Bill.Id;
            viewModel.Bill.IBAN = provider.Bill.IBAN;


            if (!this.IsMegaAdmin())
            {
                viewModel.SeletedOrganisationId = this.userService.GetUserOrganisationId(this.User.Identity.GetUserId());
                viewModel.Bill.Currency         = this.currencyService.GetAll()
                                                  .Where(x => x.OrganisationId == this.userService.GetUserOrganisationId(this.User.Identity.GetUserId()))
                                                  .ToList()
                                                  .ConvertAll(x =>
                                                              new CurrencyViewModel
                {
                    Code = x.Code,
                    Id   = x.Id
                })
                                                  .ToList();
            }
            else
            {
                viewModel.Bill.Currency = this.currencyService.GetAll()
                                          .Where(x => x.OrganisationId == provider.OrganisationId)
                                          .ToList()
                                          .ConvertAll(x =>
                                                      new CurrencyViewModel
                {
                    Code = x.Code,
                    Id   = x.Id
                })
                                          .ToList();
                viewModel.SeletedOrganisationId = provider.OrganisationId;
            }

            return(View(viewModel));
        }