public async Task <IActionResult> GetCantiereDetails(Cantiere c)
        {
            List <string> uriPhotos = await _cantiereRepo.GetPhotos(c.Id);

            c.UriPhotos = new List <string>();
            foreach (string uri in uriPhotos)
            {
                c.UriPhotos.Add(uri);
            }
            return(View(c));
        }
Exemple #2
0
        public async Task <IActionResult> NuovoCantiere([FromForm] Cantiere c)
        {
            Cantiere ca = new Cantiere
            {
                NomeCliente  = c.NomeCliente,
                Luogo        = c.Luogo,
                EmailCliente = c.EmailCliente
            };

            using (SqlConnection connection = new SqlConnection(""))
            {
                var query = "INSERT INTO [dbo].[Cantiere]" +
                            "([NomeCliente], [Luogo] ,[EmailCliente])  " +
                            "VALUES (@NomeCliente, @Luogo, @EmailCliente)";

                connection.Execute(query, ca);

                connection.Close();
            }

            return(View("Index"));
        }
        public async Task <IActionResult> CreateCantiere(CantiereViewModel c)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_configuration["ConnectionStrings:StorageAccountCS"]);
            CloudBlobClient     cbc            = storageAccount.CreateCloudBlobClient();

            var      photoContainer = cbc.GetContainerReference("cantieri");
            Cantiere cant           = new Cantiere
            {
                Luogo        = c.Luogo,
                EmailCliente = c.EmailCliente,
                NomeCliente  = c.NomeCliente,
                UriPhotos    = new List <string>()
            };

            foreach (var file in c.Photos)
            {
                var id            = Guid.NewGuid();
                var fileExtension = Path.GetExtension(file.FileName);

                var blobName = $"photo/{id}{fileExtension}";

                var blobRef = photoContainer.GetBlockBlobReference(blobName);


                using (var stream = file.OpenReadStream())
                {
                    await blobRef.UploadFromStreamAsync(stream);
                }


                cant.UriPhotos.Add(blobRef.Uri.AbsoluteUri);
            }


            await _cantiereRepo.CreateCantiere(cant);


            return(RedirectToAction("Index"));
        }
        public bool GetIfAttivo(Cantiere cantiere)
        {
            //_context.Interventos.FirstOrDefault() 

            return true;
        }
 public async Task DeleteCantiere(Cantiere cantiere)
 {
     cantiere.Stored = true;
     await _context.SaveChangesAsync();
 }
 public async Task UpdateCantiere(Cantiere cantiere)
 {
      _context.Update(cantiere);
      await _context.SaveChangesAsync();
 }
 public async Task AddCantiere(Cantiere cantiere)
 {
     _context.Add(cantiere);
     await _context.SaveChangesAsync();
 }
        public async Task AddIntervento(Intervento inputIntervento, Dictionary <Materiale, decimal> choosenMateriale,
                                        Dictionary <Operatore, double> operatoriCoinvolti, string description, string note, Cantiere cantiere, string data,
                                        decimal costoUrgenza, bool isUrgenza = false)
        {
            if (_context.Interventos.Contains(inputIntervento)) // if this intervento exists already
            {
                inputIntervento.CantieriId   = cantiere.Id;
                inputIntervento.Descrizione  = description;
                inputIntervento.IsUrgenza    = isUrgenza;
                inputIntervento.Data         = data == "--" ? new DateTime() : DateTime.Parse(data);
                inputIntervento.CostoUrgenza = costoUrgenza;
                inputIntervento.Note         = note;
                _context.Interventos.Update(inputIntervento);

                foreach (var operatore in operatoriCoinvolti)
                {
                    var existingInterventoOperatore =
                        _context.InterventoOperatores.FirstOrDefault(x => x.OperatoriId == operatore.Key.Id && x.InterventiId == inputIntervento.Id);
                    if (existingInterventoOperatore != null) // the operatore exists already
                    {
                        existingInterventoOperatore.OreSpese = Convert.ToDecimal(operatore.Value);
                        _context.Update(existingInterventoOperatore);
                    }
                    else
                    {
                        var interventoOperatore = new InterventoOperatore
                        {
                            OperatoriId  = operatore.Key.Id,
                            OreSpese     = Convert.ToDecimal(operatore.Value),
                            InterventiId = inputIntervento.Id
                        };

                        _context.Add(interventoOperatore);
                    }
                }

                var interventoMateriali = new List <InterventoMateriale>();
                foreach (var materiale in choosenMateriale)
                {
                    var existingMateriale = _context.InterventoMateriales.FirstOrDefault(x => x.MaterialeId == materiale.Key.Id && x.InterventiId == inputIntervento.Id);
                    if (existingMateriale != null) // the materiale exists already
                    {
                        existingMateriale.Quantita = materiale.Value;
                        _context.Update(existingMateriale);
                    }
                    else
                    {
                        var interventoMateriale = new InterventoMateriale
                        {
                            MaterialeId  = materiale.Key.Id,
                            Quantita     = materiale.Value,
                            InterventiId = inputIntervento.Id
                        };

                        _context.Add(interventoMateriale);
                    }
                }
            }
            else
            {
                var intervento = new Intervento
                {
                    CantieriId   = cantiere.Id,
                    Descrizione  = description,
                    IsUrgenza    = isUrgenza,
                    Data         = data == "--" ? new DateTime() : DateTime.Parse(data),
                    CostoUrgenza = costoUrgenza,
                    Note         = note
                };
                _context.Interventos.Add(intervento);
                _context.SaveChanges();

                var interventoOperatore = new List <InterventoOperatore>();
                foreach (var operatore in operatoriCoinvolti)
                {
                    interventoOperatore.Add(new InterventoOperatore
                    {
                        OperatoriId  = operatore.Key.Id,
                        OreSpese     = Convert.ToDecimal(operatore.Value),
                        InterventiId = intervento.Id
                    });
                }

                _context.AddRange(interventoOperatore);
                _context.SaveChanges();

                var interventoMateriali = new List <InterventoMateriale>();
                foreach (var materiale in choosenMateriale)
                {
                    interventoMateriali.Add(new InterventoMateriale
                    {
                        MaterialeId  = materiale.Key.Id,
                        Quantita     = materiale.Value,
                        InterventiId = intervento.Id
                    });
                }

                _context.AddRange(interventoMateriali);
                _context.SaveChanges();
            }

            await _context.SaveChangesAsync();
        }