コード例 #1
0
        public async Task <Production> AddProduction(ModelViewProduction modelViewProduction)
        {
            Production production = null;

            try
            {
                Etablissement etablissement = await GetEtablissementByUser();

                if (etablissement.Installation.Production == null)
                {
                    production = new Production()
                    {
                        Identification         = modelViewProduction.Identification,
                        NombreBallon           = modelViewProduction.NombreBallon,
                        TemperatureBouclageEcs = modelViewProduction.TemperatureBouclageEcs,
                        TemperatureDepartEcs   = modelViewProduction.TemperatureDepartEcs,
                        InstallationId         = etablissement.Installation.Id
                    };
                    production.TypeProduction = await _context.TypeProductions.FindAsync(modelViewProduction.TypeProductionId);

                    production.TypeReseau = await _context.TypeReseaus.FindAsync(modelViewProduction.TypeReseauId);

                    _context.Add(production);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(production);
        }
コード例 #2
0
        public async Task <ModelViewProduction> GetProductionModelView()
        {
            ModelViewProduction modelViewProduction = null;

            try
            {
                Etablissement etablissement = await GetEtablissementByUser();

                Production production = await _context.Productions
                                        .Include(p => p.TypeProduction)
                                        .Include(p => p.TypeReseau)
                                        .Where(p => p.InstallationId == etablissement.Installation.Id).FirstOrDefaultAsync();

                modelViewProduction = new ModelViewProduction()
                {
                    Id                     = production.Id,
                    Identification         = production.Identification,
                    InstallationId         = production.InstallationId,
                    NombreBallon           = production.NombreBallon,
                    TemperatureBouclageEcs = production.TemperatureBouclageEcs,
                    TemperatureDepartEcs   = production.TemperatureDepartEcs,
                    TypeProductionId       = production.TypeProduction.Id,
                    TypeReseauId           = production.TypeReseau.Id
                };
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(modelViewProduction);
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Identification,NombreBallon,TemperatureDepartEcs,TemperatureBouclageEcs,TypeReseauId,TypeProductionId")] ModelViewProduction production)
        {
            if (id != production.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!await _dataProduction.EditProduction(production))
                    {
                        return(NotFound());
                    }
                }
                catch (Exception ex)
                {
                    if (!_dataProduction.ProductionExists(production.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        await _dataProduction.AddLogErreur(ex);

                        return(NotFound());
                    }
                }
                return(RedirectToAction("Details"));
            }
            return(View(production));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Identification,NombreBallon,TemperatureDepartEcs,TemperatureBouclageEcs,TypeReseauId,TypeProductionId")] ModelViewProduction modelViewProduction)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _dataProduction.AddProduction(modelViewProduction);

                    return(RedirectToAction("Details", "Productions"));
                }
                catch (Exception ex)
                {
                    await _dataProduction.AddLogErreur(ex);

                    return(NotFound());
                }
            }
            return(View(modelViewProduction));
        }
コード例 #5
0
        public async Task <bool> EditProduction(ModelViewProduction modelViewProduction)
        {
            bool IsEdited = false;

            try
            {
                Etablissement etablissement = await GetEtablissementByUser();

                if (etablissement.Installation.Production.Id == modelViewProduction.Id)
                {
                    Production production = await _context.Productions
                                            .Include(p => p.TypeProduction)
                                            .Include(p => p.TypeReseau)
                                            .Where(p => p.Id == modelViewProduction.Id)
                                            .FirstOrDefaultAsync();

                    List <TypeProduction> typeProductions = await _dataPoco.GetTypeProduction();

                    List <TypeReseau> typeReseaus = await _dataPoco.GetTypeReseau();

                    production.Identification         = modelViewProduction.Identification;
                    production.InstallationId         = etablissement.Installation.Id;
                    production.NombreBallon           = modelViewProduction.NombreBallon;
                    production.TemperatureBouclageEcs = modelViewProduction.TemperatureBouclageEcs;
                    production.TemperatureDepartEcs   = modelViewProduction.TemperatureDepartEcs;

                    production.TypeProduction = typeProductions.Where(p => p.Id == modelViewProduction.TypeProductionId).FirstOrDefault();
                    production.TypeReseau     = typeReseaus.Where(p => p.Id == modelViewProduction.TypeReseauId).FirstOrDefault();

                    _context.Update(production);
                    await _context.SaveChangesAsync();

                    IsEdited = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(IsEdited);
        }
コード例 #6
0
        // GET: Productions/Edit/5
        public async Task <IActionResult> Edit()
        {
            ModelViewProduction modelViewProduction = null;

            try
            {
                modelViewProduction = await _dataProduction.GetProductionModelView();

                ViewBag.TypeReseau     = new SelectList(_context.TypeReseaus, "Id", "Nom");
                ViewBag.TypeProduction = new SelectList(_context.TypeProductions, "Id", "Nom");
            }
            catch (Exception ex)
            {
                await _dataProduction.AddLogErreur(ex);
            }
            if (modelViewProduction == null)
            {
                return(NotFound());
            }
            return(View(modelViewProduction));
        }