Ejemplo n.º 1
0
 public AdherentsViewModel(AdherentStolon activeAdherentStolon, Stolon stolon, List <Sympathizer> sympathizers, List <AdherentStolon> adherentsStolon)
 {
     AdherentsStolonViewModel = new AdherentsStolonViewModel(activeAdherentStolon, stolon, adherentsStolon);
     ActiveAdherentStolon     = activeAdherentStolon;
     SympathizersViewModel    = new SympathizersViewModel(activeAdherentStolon, stolon, sympathizers);
     Stolon = stolon;
 }
Ejemplo n.º 2
0
 public ProductEditionViewModel(AdherentStolon activeAdherentStolon, Product product, ApplicationDbContext context, bool isNew)
 {
     ActiveAdherentStolon = activeAdherentStolon;
     Product = product;
     IsNew   = isNew;
     RefreshTypes(context);
 }
Ejemplo n.º 3
0
 public SelectAdherentViewModel(AdherentStolon activeAdherent, Stolon stolon, List <string> adherentsMails, bool addHasProducer)
 {
     base.ActiveAdherentStolon = activeAdherent;
     AdherentsMails            = adherentsMails;
     Stolon         = stolon;
     AddHasProducer = addHasProducer;
 }
Ejemplo n.º 4
0
        // GET: WeekBasket/Index/id
        public IActionResult Index()
        {
            AdherentStolon adherentStolon = GetActiveAdherentStolon();

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

            TempWeekBasket      tempWeekBasket      = _context.TempsWeekBaskets.Include(x => x.AdherentStolon).Include(x => x.AdherentStolon.Adherent).Include(x => x.BillEntries).FirstOrDefault(x => x.AdherentStolon.Id == adherentStolon.Id);
            ValidatedWeekBasket validatedWeekBasket = _context.ValidatedWeekBaskets.Include(x => x.AdherentStolon).Include(x => x.AdherentStolon.Adherent).Include(x => x.BillEntries).FirstOrDefault(x => x.AdherentStolon.Id == adherentStolon.Id);

            if (tempWeekBasket == null)
            {
                //Il n'a pas encore de panier de la semaine, on lui en crée un
                tempWeekBasket = new TempWeekBasket
                {
                    AdherentStolon = adherentStolon,
                    BillEntries    = new List <BillEntry>()
                };
                _context.Add(tempWeekBasket);
                _context.SaveChanges();
            }
            return(View(new WeekBasketViewModel(adherentStolon, tempWeekBasket, validatedWeekBasket, _context)));
        }
Ejemplo n.º 5
0
        public virtual IActionResult AddAdherent(SelectAdherentViewModel selectAdherentViewModel)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                AdherentStolon adherentStolon = new AdherentStolon(_context.Adherents.First(x => x.Email == selectAdherentViewModel.SelectedEmail.Trim()), _context.Stolons.First(x => x.Id == selectAdherentViewModel.Stolon.Id));
                adherentStolon.RegistrationDate = DateTime.Now;
                if (_context.AdherentStolons.Where(x => x.StolonId == selectAdherentViewModel.Stolon.Id).Any())
                {
                    adherentStolon.LocalId = _context.AdherentStolons.Where(x => x.StolonId == selectAdherentViewModel.Stolon.Id).Max(x => x.LocalId) + 1;
                }
                else
                {
                    adherentStolon.LocalId = 1;
                }
                _context.AdherentStolons.Add(adherentStolon);
                _context.SaveChanges();
                if (selectAdherentViewModel.AddHasProducer)
                {
                    SetAsProducer(adherentStolon.Id);
                }
                //Send confirmation mail
                Services.AuthMessageSender.SendEmail(adherentStolon.Stolon.Label, adherentStolon.Adherent.Email, adherentStolon.Adherent.Name, "Adhésion à un nouveau Stolon", base.RenderPartialViewToString("AdherentConfirmationMail", adherentStolon));

                return(RedirectToAction("Index"));
            }
            return(View(selectAdherentViewModel));
        }
Ejemplo n.º 6
0
        public virtual PartialViewResult _PartialDisableAdherent(Guid id, Guid?stolonId = null)
        {
            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).Include(x => x.Stolon).FirstOrDefault(x => x.Id == id);


            return(PartialView(new DisableAccountViewModel(GetActiveAdherentStolon(), adherentStolon)));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Pay subscription
        /// </summary>
        /// <param name="id">AdherentStolon id</param>
        /// <returns></returns>
        public IActionResult PaySubscription(Guid id)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }
            //Adherent stolon
            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Stolon).Include(x => x.Adherent).First(x => x.Id == id);

            adherentStolon.SubscriptionPaid = true;
            _context.AdherentStolons.Update(adherentStolon);
            //Transaction
            Transaction transaction = new Transaction();

            transaction = new AdherentTransaction()
            {
                Adherent = adherentStolon.Adherent
            };
            //Update
            transaction.Amount = Configurations.GetSubscriptionAmount(adherentStolon);
            //Add a transaction
            transaction.Stolon           = adherentStolon.Stolon;
            transaction.AddedAutomaticly = true;
            transaction.Date             = DateTime.Now;
            transaction.Type             = Transaction.TransactionType.Inbound;
            transaction.Category         = Transaction.TransactionCategory.Subscription;
            transaction.Description      = "Paiement de la cotisation de l'adhérant " + (adherentStolon.IsProducer?"producteur":"") + " : " + adherentStolon.Adherent.Name + " " + adherentStolon.Adherent.Surname;
            _context.Transactions.Add(transaction);
            //Save
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
 public WeekBasketViewModel(AdherentStolon adherentStolon, TempWeekBasket tempWeekBasket, ValidatedWeekBasket validatedWeekBasket, ApplicationDbContext context)
 {
     TempWeekBasket      = tempWeekBasket;
     ValidatedWeekBasket = validatedWeekBasket;
     AdherentStolon      = adherentStolon;
     ProductsStocks      = context.ProductsStocks.Include(x => x.Product).Include(x => x.AdherentStolon).Where(x => x.AdherentStolon.Id == AdherentStolon.Stolon.Id).Where(x => x.Product.IsAvailable).Where(x => x.State == Product.ProductState.Enabled).ToList();
     ProductTypes        = context.ProductTypes.Include(x => x.ProductFamilly).ToList();
 }
Ejemplo n.º 9
0
 public AdherentViewModel(AdherentStolon activeAdherentStolon, Adherent adherent, Stolon stolon, AdherentEdition edition)
 {
     Adherent             = adherent;
     OriginalEmail        = adherent.Email;
     ActiveAdherentStolon = activeAdherentStolon;
     Edition = edition;
     Stolon  = stolon;
 }
Ejemplo n.º 10
0
        public IActionResult SetAsAdherent(Guid?id)
        {
            AdherentStolon adherentStolon = _context.AdherentStolons.First(x => x.Id == id);

            adherentStolon.Role = Role.Adherent;
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 11
0
        public IActionResult SetAsConsumer(Guid?id)
        {
            AdherentStolon adherentStolon = _context.AdherentStolons.First(x => x.Id == id);

            adherentStolon.IsProducer = false;
            _context.ProductsStocks.RemoveRange(_context.ProductsStocks.Where(x => x.AdherentStolonId == adherentStolon.Id));
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
        private static void CreateAcount(ApplicationDbContext context, UserManager <ApplicationUser> userManager, string name, string surname, string email, string password, Role role, Stolon stolon, bool isWebAdmin, bool isProducer = false, bool createOnlyIfTableEmpty = false)
        {
            if (createOnlyIfTableEmpty)
            {
                if (isProducer)
                {
                    if (context.AdherentStolons.Any(x => x.IsProducer))
                    {
                        return;
                    }
                }
            }

            if (context.Adherents.Any(x => x.Email == email))
            {
                return;
            }
            Adherent adherent = new Adherent();

            adherent.Name       = name;
            adherent.Surname    = surname;
            adherent.Email      = email;
            adherent.PostCode   = "07000";
            adherent.IsWebAdmin = isWebAdmin;

            AdherentStolon adherentStolon = new AdherentStolon(adherent, stolon, true)
            {
                RegistrationDate = DateTime.Now,
                Enable           = true,
                Role             = role
            };

            adherentStolon.LocalId = context.AdherentStolons.Where(x => x.StolonId == stolon.Id).Select(x => x.LocalId).DefaultIfEmpty(0).Max() + 1;

            if (isProducer)
            {
                adherent.CompanyName      = "La ferme de " + adherent.Name;
                adherent.Latitude         = 44.7354673;
                adherent.Longitude        = 4.601407399999971;
                adherentStolon.IsProducer = true;
            }

            context.Adherents.Add(adherent);
            context.AdherentStolons.Add(adherentStolon);
            context.SaveChanges();

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

            userManager.CreateAsync(appUser, password).Wait();
            #endregion Creating linked application data
        }
Ejemplo n.º 13
0
        public bool Authorized(Role role)
        {
            //Check if user is Authentified
            if (!User.Identity.IsAuthenticated)
            {
                return(false);
            }
            AdherentStolon adherentStolon = GetActiveAdherentStolon();

            return(adherentStolon.Authorized(role));
        }
Ejemplo n.º 14
0
        public IActionResult UnSetAsWebAdmin(Guid?id)
        {
            if (!AuthorizedWebAdmin())
            {
                return(Unauthorized());
            }
            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).First(x => x.Id == id);

            adherentStolon.Adherent.IsWebAdmin = false;
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 15
0
        public IActionResult SetAsAdmin(Guid?id)
        {
            if (!Authorized(Role.Admin))
            {
                return(Unauthorized());
            }
            AdherentStolon adherentStolon = _context.AdherentStolons.First(x => x.Id == id);

            adherentStolon.Role = Role.Admin;
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
        // GET: Consumers/Edit/5
        public IActionResult Edit()
        {
            AdherentStolon adherentStolon = GetActiveAdherentStolon();

            if (adherentStolon == null)
            {
                return(NotFound());
            }
            bool isProducer = _context.AdherentStolons.Any(x => x.IsProducer && x.AdherentId == adherentStolon.AdherentId);

            return(View(new AdherentViewModel(adherentStolon, adherentStolon.Adherent, adherentStolon.Stolon, isProducer? AdherentEdition.Producer: AdherentEdition.Consumer)));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Set as producer the specified adherent stolon
        /// </summary>
        /// <param name="id">Adherent Stolon Id</param>
        public IActionResult SetAsProducer(Guid?id)
        {
            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).ThenInclude(x => x.Products).First(x => x.Id == id);

            adherentStolon.IsProducer = true;
            foreach (var product in adherentStolon.Adherent.Products)
            {
                _context.ProductsStocks.Add(new ProductStockStolon(product.Id, adherentStolon.Id));
            }
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                //D'abord on regarde si il existe bien un User avec ce mail
                Adherent stolonsUser = _context.Adherents.Include(x => x.AdherentStolons).FirstOrDefault(x => model.Email.Equals(x.Email, StringComparison.CurrentCultureIgnoreCase));
                if (stolonsUser == null)
                {
                    ModelState.AddModelError("LoginFailed", "Utilisateur inconnu");
                    return(View(model));
                }
                else
                {
                    AdherentStolon activeAdherentStolon = stolonsUser.AdherentStolons.First(x => x.IsActiveStolon);
                    //On regarde si le compte de l'utilisateur est actif
                    if (!activeAdherentStolon.Enable)
                    {
                        var otherAdherentStolon = stolonsUser.AdherentStolons.FirstOrDefault(x => x.Enable && x.Id != activeAdherentStolon.Id && x.AdherentId == activeAdherentStolon.AdherentId);
                        if (otherAdherentStolon == null)
                        {
                            ModelState.AddModelError("LoginFailed", "Votre compte a été bloqué pour la raison suivante : " + activeAdherentStolon.DisableReason);
                            return(View(model));
                        }
                        else
                        {
                            otherAdherentStolon.SetHasActiveStolon(_context);
                        }
                    }
                    // Il a un mot de passe, on le log si il est bon
                    // This doesn't count login failures towards account lockout
                    // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                    var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                    if (result.Succeeded)
                    {
                        return(RedirectToLocal(returnUrl));
                    }
                    if (result.IsLockedOut)
                    {
                        return(View("Lockout"));
                    }
                    else
                    {
                        ModelState.AddModelError("LoginFailed", "Erreur dans la saisie du mot de passe");
                        return(View(model));
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 19
0
        // GET: Stolons
        public override IActionResult Index()
        {
            if (!AuthorizedWebAdmin())
            {
                return(Unauthorized());
            }
            AdherentStolon            activeAdherentStolon = GetActiveAdherentStolon();
            List <AdherentsViewModel> adherentsViewModel   = new List <AdherentsViewModel>();

            foreach (var stolon in _context.Stolons.ToList())
            {
                adherentsViewModel.Add(new AdherentsViewModel(activeAdherentStolon, stolon, _context.Sympathizers.Where(x => x.StolonId == stolon.Id).ToList(), _context.AdherentStolons.Include(x => x.Stolon).Include(x => x.Adherent).Where(x => x.StolonId == stolon.Id).ToList()));
            }
            ViewData["Controller"] = "Stolons";
            return(View(new StolonsViewModel(GetActiveAdherentStolon(), adherentsViewModel)));
        }
Ejemplo n.º 20
0
        private static T CreateBill <T>(AdherentStolon adherentStolon, List <BillEntry> billEntries) where T : class, IBill, new()
        {
            IBill bill = new T();

            bill.BillId      = Guid.NewGuid();
            bill.BillEntries = billEntries;
            bill.BillNumber  = GenerateBillNumber(adherentStolon.Stolon.ShortLabel, adherentStolon.LocalId, bill is ProducerBill);
            if (bill is ProducerBill)
            {
                (bill as ProducerBill).OrderNumber = GenerateOrderNumber(adherentStolon.Stolon.ShortLabel, adherentStolon.LocalId);
            }
            bill.AdherentStolon = adherentStolon;
            bill.State          = BillState.Pending;
            bill.EditionDate    = DateTime.Now;
            return(bill as T);
        }
Ejemplo n.º 21
0
        public IActionResult EnableAdherent(Guid id)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }

            AdherentStolon adherentStolon = _context.AdherentStolons.First(x => x.Id == id);

            adherentStolon.DisableReason = "";
            adherentStolon.Enable        = true;
            //Update
            _context.AdherentStolons.Update(adherentStolon);
            //Save
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 22
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));
        }
Ejemplo n.º 23
0
        public virtual IActionResult DeleteConfirmed(Guid id)
        {
            if (!Authorized(Role.Admin))
            {
                return(Unauthorized());
            }

            AdherentStolon adherentStolon = _context.AdherentStolons.First(x => x.Id == id);

            //Check if adherent is in an other Stolons
            if (_context.AdherentStolons.Any(x => x.AdherentId == adherentStolon.AdherentId && x.StolonId != adherentStolon.StolonId))
            {
            }
            //Delete the adherent from this stolons
            _context.AdherentStolons.Remove(adherentStolon);
            //Save
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 24
0
        public IActionResult DeleteAdherent(Guid id)
        {
            if (!Authorized(Role.Admin))
            {
                return(Unauthorized());
            }

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

            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).Include(x => x.Stolon).FirstOrDefault(x => x.Id == id);

            if (adherentStolon == null)
            {
                return(NotFound());
            }
            return(View(new AdherentStolonViewModel(GetActiveAdherentStolon(), adherentStolon)));
        }
Ejemplo n.º 25
0
        public IActionResult EditAdherent(Guid id)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }

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

            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).Include(x => x.Stolon).FirstOrDefault(x => x.Id == id);

            if (adherentStolon == null)
            {
                return(NotFound());
            }
            return(View(new AdherentViewModel(GetActiveAdherentStolon(), adherentStolon.Adherent, adherentStolon.Stolon, AdherentEdition.Consumer)));
        }
Ejemplo n.º 26
0
        public IActionResult CreditToken(CreditTokenViewModel vmCreditToken)
        {
            if (!Authorized(Role.Volunteer))
            {
                return(Unauthorized());
            }

            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).First(x => x.Id == vmCreditToken.AdherentStolon.Id);

            adherentStolon.Token += vmCreditToken.CreditedToken;
            _context.Add(new AdherentTransaction(
                             adherentStolon.Adherent,
                             adherentStolon.Stolon,
                             Transaction.TransactionType.Inbound,
                             Transaction.TransactionCategory.TokenCredit,
                             vmCreditToken.CreditedToken,
                             "Encaissement de " + vmCreditToken.CreditedToken + "€, pour créditage du compte de " + adherentStolon.Adherent.Name + "( " + adherentStolon.LocalId + " ) de " + vmCreditToken.CreditedToken + "Ṩ"));
            _context.Update(adherentStolon);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 27
0
        public static decimal GetSubscriptionAmount(AdherentStolon adherentStolon)
        {
            int currentMonth      = DateTime.Now.Month - 6;
            int subscriptionMonth = (int)adherentStolon.Stolon.SubscriptionStartMonth;

            if (currentMonth < subscriptionMonth)
            {
                currentMonth += 12;
            }
            bool isHalfSubscription = currentMonth > (subscriptionMonth + 6);

            //
            if (adherentStolon.IsProducer)
            {
                return(isHalfSubscription ? adherentStolon.Stolon.ProducerSubscription / 2 : adherentStolon.Stolon.ProducerSubscription);
            }
            else
            {
                return(isHalfSubscription ? adherentStolon.Stolon.ConsumerSubscription / 2 : adherentStolon.Stolon.ConsumerSubscription);
            }
        }
Ejemplo n.º 28
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            if (User.Identity.IsAuthenticated)
            {
                ApplicationUser appUser = await _userManager.FindByIdAsync(_userManager.GetUserId(HttpContext.User));

                AdherentStolon adherentStolon = _dbContext.AdherentStolons.Include(x => x.Adherent).ThenInclude(x => x.AdherentStolons).Include(x => x.Stolon).FirstOrDefault(x => x.IsActiveStolon && x.Adherent.Email.Equals(appUser.Email, StringComparison.CurrentCultureIgnoreCase));
                adherentStolon.Adherent.AdherentStolons.ForEach(x => x.Stolon = _dbContext.Stolons.First(stolon => stolon.Id == x.StolonId));
                TempWeekBasket tempWeekBasket = _dbContext.TempsWeekBaskets.Include(x => x.AdherentStolon).Include(x => x.AdherentStolon.Adherent).Include(x => x.BillEntries).FirstOrDefault(x => x.AdherentStolon.Id == adherentStolon.Id);
                if (tempWeekBasket != null)
                {
                    tempWeekBasket.Validated = WeekBasketController.IsBasketValidated(tempWeekBasket, _dbContext);
                }
                ConsumerBill consumerBill = _dbContext.ConsumerBills.FirstOrDefault(x => x.AdherentStolon.Id == adherentStolon.Id && x.State == BillState.Pending);


                return(View(new BannerViewModel(adherentStolon, tempWeekBasket, consumerBill)));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 29
0
        public virtual IActionResult DeleteAdherent(Guid id)
        {
            if (!Authorized(Role.Admin))
            {
                return(Unauthorized());
            }

            AdherentStolon adherentStolon = _context.AdherentStolons.Include(x => x.Adherent).First(x => x.Id == id);

            //We have to keep producers for bills history
            if (adherentStolon.IsProducer && _context.ProducerBills.Any(x => x.AdherentStolon.Id == adherentStolon.Id))
            {
                adherentStolon.StolonId = null;
                adherentStolon.Stolon.UserStolons.Remove(adherentStolon);
            }
            else
            {
                //Delete the adherent from this stolons
                _context.AdherentStolons.Remove(adherentStolon);
            }
            //Save
            _context.SaveChanges();
            //If there adherent is not in any stolon remove it from connexion
            if (!_context.AdherentStolons.Any(x => x.AdherentId == adherentStolon.AdherentId))
            {
                _userManager.DeleteAsync(_userManager.Users.First(x => x.Email == adherentStolon.Adherent.Email));
                _context.Adherents.Remove(_context.Adherents.First(x => x.Id == adherentStolon.AdherentId));
                _context.SaveChanges();
            }
            else
            {
                //Give the adherant a new active stolon
                _context.AdherentStolons.First(x => x.AdherentId == adherentStolon.AdherentId).SetHasActiveStolon(_context);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 30
0
        public StolonContactViewModel(Stolon stolon, List <AdherentStolon> producers, int totalProducts, AdherentStolon activeAdherentStolon = null)
        {
            ActiveAdherentStolon = activeAdherentStolon;
            Stolon        = stolon;
            Producers     = producers;
            TotalProducts = totalProducts;

            foreach (var producer in producers)
            {
                foreach (var product in producer.Adherent.Products)
                {
                    Products.Add(product);
                    if (!AvailableProductFamillyAndType.Keys.Any(x => x.Id == product.Familly.Type.Id))
                    {
                        AvailableProductFamillyAndType.Add(product.Familly.Type, new List <ProductFamilly>());
                    }

                    if (!AvailableProductFamillyAndType[product.Familly.Type].Any(x => x.Id == product.Familly.Id))
                    {
                        AvailableProductFamillyAndType[product.Familly.Type].Add(product.Familly);
                    }
                }
            }
        }