Пример #1
0
 public AdherentViewModel(AdherentStolon activeAdherentStolon, Adherent adherent, Stolon stolon, AdherentEdition edition)
 {
     Adherent             = adherent;
     OriginalEmail        = adherent.Email;
     ActiveAdherentStolon = activeAdherentStolon;
     Edition = edition;
     Stolon  = stolon;
 }
Пример #2
0
        // GET: Consumers/Create
        public virtual IActionResult CreateAdherent(AdherentEdition edition, Guid?stolonId = null)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }

            Stolon stolon = stolonId == null?GetCurrentStolon() : _context.Stolons.First(x => x.Id == stolonId);

            return(View(new AdherentViewModel(GetActiveAdherentStolon(), new Adherent(), stolon, edition)));
        }
Пример #3
0
        public virtual PartialViewResult _PartialAddAdherent(AdherentEdition edition, Guid?stolonId = null)
        {
            Stolon stolon = stolonId == null?GetCurrentStolon() : _context.Stolons.First(x => x.Id == stolonId);

            List <string> emails;

            if (edition == AdherentEdition.Producer)
            {
                emails = _context.Adherents.Include(x => x.AdherentStolons).Where(x => x.AdherentStolons.Any(prod => prod.IsProducer)).Select(x => x.Email).ToList();
            }
            else
            {
                emails = _context.Adherents.Select(x => x.Email).ToList();
            }
            _context.AdherentStolons.Include(x => x.Adherent).Where(x => x.StolonId == stolon.Id).ToList().ForEach(x => emails.Remove(x.Adherent.Email));
            return(PartialView(new SelectAdherentViewModel(GetActiveAdherentStolon(), stolon, emails, edition == AdherentEdition.Producer)));
        }
Пример #4
0
        public virtual async Task <IActionResult> Create(AdherentEdition edition, AdherentViewModel vmAdherent, IFormFile uploadFile)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                Stolon stolon = _context.Stolons.FirstOrDefault(x => x.Id == vmAdherent.Stolon.Id);
                #region Creating Consumer
                //Setting value for creation
                UploadAndSetAvatar(vmAdherent.Adherent, uploadFile);

                vmAdherent.Adherent.Name = vmAdherent.Adherent.Name.ToUpper();
                AdherentStolon adherentStolon = new AdherentStolon(vmAdherent.Adherent, stolon, true);
                adherentStolon.RegistrationDate = DateTime.Now;
                adherentStolon.LocalId          = _context.AdherentStolons.Where(x => x.StolonId == stolon.Id).Max(x => x.LocalId) + 1;
                adherentStolon.IsProducer       = edition == AdherentEdition.Producer;
                _context.Adherents.Add(vmAdherent.Adherent);
                _context.AdherentStolons.Add(adherentStolon);
                #endregion Creating Consumer

                #region Creating linked application data
                var appUser = new ApplicationUser {
                    UserName = vmAdherent.Adherent.Email, Email = vmAdherent.Adherent.Email
                };
                appUser.User = vmAdherent.Adherent;

                var result = await _userManager.CreateAsync(appUser, vmAdherent.Adherent.Email);

                #endregion Creating linked application data
                //
                //
                _context.SaveChanges();
                //Send confirmation mail
                string confirmationViewName = edition == AdherentEdition.Consumer ? "AdherentConfirmationMail" : "ProducerConfirmationMail";
                Services.AuthMessageSender.SendEmail(stolon.Label, vmAdherent.Adherent.Email, vmAdherent.Adherent.Name, "Creation de votre compte", base.RenderPartialViewToString(confirmationViewName, adherentStolon));

                return(RedirectToAction("Index"));
            }
            return(View(vmAdherent));
        }
Пример #5
0
        public virtual PartialViewResult _PartialCreateAdherent(AdherentEdition edition, Guid?stolonId = null)
        {
            Stolon stolon = stolonId == null?GetCurrentStolon() : _context.Stolons.First(x => x.Id == stolonId);

            return(PartialView(new AdherentViewModel(GetActiveAdherentStolon(), new Adherent(), stolon, edition)));
        }