示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Pk,FkMateriels,FkMaterielsStatuts,FkIxAntenne,FkAspNetUsers,DateDebut,DateFin,Commentaire")] LinksMaterielsIxMaterielStatuts linksMaterielsIxMaterielStatuts)
        {
            string mailsend = string.Empty;
            string sujet    = string.Empty;
            string message  = string.Empty;

            if (id != linksMaterielsIxMaterielStatuts.Pk)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (linksMaterielsIxMaterielStatuts.FkMaterielsStatuts == 6)
                    {
                        linksMaterielsIxMaterielStatuts.DateFin = DateTime.Now.ToString("dd MMMM yyyy");
                    }
                    else
                    {
                        linksMaterielsIxMaterielStatuts.DateFin = null;
                    }
                    _context.Update(linksMaterielsIxMaterielStatuts);
                    mailsend = _context.AspNetUsers.First(c => c.Id == linksMaterielsIxMaterielStatuts.FkAspNetUsers).UserName;
                    message  = _context.Materiels.First(c => c.PkMateriels == linksMaterielsIxMaterielStatuts.FkMateriels).Identifiant;
                    await email.SendEmailAsync(mailsend, "matériel modifié", "Bonjour, \n Votre demande concernant le " + message + " a été modifié. \n Cordialement,");

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LinksMaterielsIxMaterielStatutsExists(linksMaterielsIxMaterielStatuts.Pk))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FkAspNetUsers"]      = new SelectList(_context.AspNetUsers, "Id", "Id", linksMaterielsIxMaterielStatuts.FkAspNetUsers);
            ViewData["FkIxAntenne"]        = new SelectList(_context.IxAntenne, "PkAntenne", "PkAntenne", linksMaterielsIxMaterielStatuts.FkIxAntenne);
            ViewData["FkMateriels"]        = new SelectList(_context.Materiels, "PkMateriels", "PkMateriels", linksMaterielsIxMaterielStatuts.FkMateriels);
            ViewData["FkMaterielsStatuts"] = new SelectList(_context.IxMaterielsStatuts, "PkIxMaterielsStatuts", "PkIxMaterielsStatuts", linksMaterielsIxMaterielStatuts.FkMaterielsStatuts);
            return(View(linksMaterielsIxMaterielStatuts));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Pk,FkMateriels,FkMaterielsStatuts,FkIxAntenne,FkAspNetUsers,DateDebut,DateFin,Commentaire")] LinksMaterielsIxMaterielStatuts linksMaterielsIxMaterielStatuts)
        {
            if (ModelState.IsValid)
            {
                _context.Add(linksMaterielsIxMaterielStatuts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();
            }
            ViewData["FkAspNetUsers"]      = new SelectList(_context.AspNetUsers, "Id", "UserName");
            ViewData["FkIxAntenne"]        = new SelectList(_context.IxAntenne, "PkAntenne", "Ville");
            ViewData["FkMateriels"]        = new SelectList(_context.Materiels, "PkMateriels", "Identifiant");
            ViewData["FkMaterielsStatuts"] = new SelectList(_context.IxMaterielsStatuts, "PkIxMaterielsStatuts", "MaterielStatut");
            return(View(linksMaterielsIxMaterielStatuts));
        }