Ejemplo n.º 1
0
        public async Task <IActionResult> Create(AddProviderViewModel model)
        {
            if (ModelState.IsValid)
            {
                var provider = await _context.Providers.FirstOrDefaultAsync
                                   (sc => sc.Name.ToUpper() == model.Name.ToUpper());

                if (provider != null)
                {
                    var error = "The Provider can't be Added because it already exists.";
                    return(RedirectToAction("Index", new RouteValueDictionary(new { Controller = "Provider", error })));
                }
                var path = string.Empty;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile, "Providers");
                }

                provider = _converterHelper.ToProviderEntity(model, path);

                _context.Providers.Add(provider);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult AddProvider(AddProviderViewModel model, String roleName)
        {
            if (ModelState.IsValid)
            {
                if (model.MiddleName == null)
                {
                    model.MiddleName = string.Empty;
                }
                var user = new ApplicationUser
                {
                    UserName       = model.UserName,
                    FirstName      = model.FirstName,
                    MiddleName     = model.MiddleName,
                    LastName       = model.LastName,
                    Email          = model.Email,
                    EmailConfirmed = true,
                    IsActive       = true
                };
                var ctx     = new ApplicationDbContext();
                var oldUser = ctx.Providers.FirstOrDefault(u => u.User.FirstName == model.FirstName && u.User.LastName == model.LastName && u.User.MiddleName == model.MiddleName && u.User.UserName == model.UserName && u.DateOfBirth == model.DateOfBirth);
                // bool exist =  oldUser!= null ? true : false;
                if (oldUser != null)
                {
                    oldUser.User.IsActive = true;
                    ctx.SaveChanges();
                    return(RedirectToAction("Providers", "Provider"));
                }
                else
                {
                    var result = UserManager.Create(user, model.Password);
                    if (result.Succeeded)
                    {
                        IdentityResult roleAdd = UserManager.AddToRole(user.Id, roleName);
                        using (var db = new ApplicationDbContext())
                        {
                            db.Providers.Add(new Provider {
                                ProviderId = user.Id, DateOfBirth = model.DateOfBirth
                            });
                            db.SaveChanges();

                            return(RedirectToAction("Providers", "Provider"));
                        }
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            var ctxt = new ApplicationDbContext();
            IEnumerable <string> rolels = from role in ctxt.Roles.ToList()
                                          where role.Name != "Clerk" && role.Name != "Administrator"
                                          select role.Name;

            var listlt = new SelectList(rolels.ToList());

            ViewBag.Roles = listlt;
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public IActionResult AddProvider(AddProviderViewModel viewModel)
 {
     return(RedirectToRoute("AddProviderDetail", new
     {
         ukPrn = viewModel.UkPrn,
         name = viewModel.Name
     }));
 }
Ejemplo n.º 4
0
 public ProviderEntity ToProviderEntity(AddProviderViewModel model, string path)
 {
     return(new ProviderEntity
     {
         Id = model.Id,
         Name = model.Name,
         ImageUrl = path
     });
 }
 public IActionResult AddProviderDetail(AddProviderViewModel viewModel)
 {
     return(View("ProviderDetail", new ProviderDetailViewModel
     {
         Name = viewModel.Name,
         DisplayName = viewModel.Name.ToTitleCase(),
         UkPrn = viewModel.UkPrn
     }));
 }
        public async Task <IActionResult> Add(IFormFile uploadedFile, [FromForm] AddProviderViewModel 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}");
                        }
                    }

                    providerDto = new ProviderDTO
                    {
                        Email        = model.Email,
                        Info         = model.Info,
                        IsActive     = model.IsActive,
                        IsFavorite   = model.IsFavorite,
                        Name         = model.Name,
                        Path         = path,
                        TimeWorkTo   = model.TimeWorkTo,
                        TimeWorkWith = model.TimeWorkWith,
                        WorkingDays  = model.WorkingDays
                    };

                    _providerService.AddProvider(providerDto);

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

                    return(RedirectToAction("Index"));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError(ex.Property, ex.Message);
                    _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
                }
            }
            return(View(model));
        }
Ejemplo n.º 7
0
        public When_Provider_Controller_AddProvider_Post_Is_Called()
        {
            var providerService = Substitute.For <IProviderService>();

            var providerController   = new ProviderController(providerService, new MatchingConfiguration());
            var controllerWithClaims = new ClaimsBuilder <ProviderController>(providerController).Build();

            var viewModel = new AddProviderViewModel
            {
                UkPrn = 123,
                Name  = "ProviderName"
            };

            _result = controllerWithClaims.AddProvider(viewModel);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, AddProviderViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var path = model.ImageUrl;

                    if (model.ImageFile != null)
                    {
                        path = await _imageHelper.UploadImageAsync(model.ImageFile, "Providers");

                        //TODO: investigar borrar imagen anterior
                        _imageHelper.DeleteImageAsync(model.ImageUrl);
                    }
                    var ProviderEntity = _converterHelper.ToProviderEntity(model, path);
                    _context.Providers.Update(ProviderEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProviderEntityExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var model = await _context.Providers.FindAsync(id);

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

            var providerviewmodel = new AddProviderViewModel
            {
                Id = model.Id,
                ProviderDetails = model.ProviderDetails,
                ImageUrl        = model.ImageUrl,
                Name            = model.Name
            };

            return(View(providerviewmodel));
        }
        public ActionResult Add()
        {
            var viewModel = new AddProviderViewModel();

            viewModel.Bill = new AddBillProviderViewModel();


            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,
                    //IsBase = x.IsBase
                })
                                                  .ToList();
            }
            else
            {
                viewModel.Bill.Currency = new List <CurrencyViewModel>();

                viewModel.Organisations = this.organisationService.GetAll().ToList()
                                          .ConvertAll(x => new OrganisationViewModel
                {
                    Id   = x.Id,
                    Name = x.Name
                });
            }

            return(View(viewModel));
        }
        public ActionResult Add(AddProviderViewModel 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,
                        //IsBase = x.IsBase
                    })
                                                  .ToList();
                }
                else
                {
                    model.Organisations = this.organisationService.GetAll().ToList()
                                          .ConvertAll(x => new OrganisationViewModel
                    {
                        Id   = x.Id,
                        Name = x.Name
                    });

                    model.Bill.Currency = this.currencyService.GetAll()
                                          .Where(x => x.OrganisationId == model.SeletedOrganisationId)
                                          .ToList()
                                          .ConvertAll(x =>
                                                      new CurrencyViewModel
                    {
                        Code = x.Code,
                        Id   = x.Id,
                        //IsBase = x.IsBase
                    })
                                          .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.Exist(model.Email, userORg))
            {
                this.ModelState.AddModelError("", ProviderTr.ExistSameEmail);

                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,
                        //IsBase = x.IsBase
                    })
                                                  .ToList();
                }
                else
                {
                    model.Organisations = this.organisationService.GetAll().ToList()
                                          .ConvertAll(x => new OrganisationViewModel
                    {
                        Id   = x.Id,
                        Name = x.Name
                    });

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

            var billId = this.billService.Add(new Bill
            {
                IBAN       = model.Bill.IBAN,
                CurrencyId = model.Bill.SelectedCurrency
            });

            var provider = new Provider
            {
                Status         = "Active",
                Phone          = model.Phone,
                Name           = model.Name,
                Email          = model.Email,
                BillId         = billId,
                Bulstat        = model.Bulstat,
                Address        = model.Address,
                OrganisationId = model.SeletedOrganisationId
            };

            this.providerService.Add(provider);

            return(Redirect("/HelpModule/Provider/GetAll"));
        }
Ejemplo n.º 12
0
 public AddProviderCommand(IProviderService providerDataService, AddProviderViewModel addProvideriewModel)
 {
     _providerDataService = providerDataService;
     _addProvideriewModel = addProvideriewModel;
 }
Ejemplo n.º 13
0
 public AddProviderDialog()
 {
     DataContext = new AddProviderViewModel();
     this.InitializeComponent();
 }