Example #1
0
        public IActionResult Dodaj(DodajDioVM model, IFormFile Slika)
        {
            if (ModelState.IsValid)
            {
                Dio dio = new Dio()
                {
                    Naziv         = model.Naziv,
                    Opis          = model.Opis,
                    Cijena        = model.Cijena,
                    ProizvodjacID = model.ProizvodjacId,
                };

                if (Slika == null || Slika.Length == 0)
                {
                    dio.Slika = new byte[0];
                }
                else
                {
                    using (var ms = new MemoryStream())
                    {
                        Slika.CopyTo(ms);
                        dio.Slika = ms.ToArray();
                    }
                }


                db.Dio.Add(dio);
                db.SaveChanges();
                if (model.DioStanja_Lokacije != null && model.DioStanja_Sifre != null)
                {
                    for (int i = 0; i < model.DioStanja_Lokacije.Count; i++)
                    {
                        DioStanje stanje = new DioStanje
                        {
                            DioId      = dio.DioId,
                            LokacijaId = model.DioStanja_Lokacije[i],
                            Sifra      = model.DioStanja_Sifre[i]
                        };
                        db.DioStanje.Add(stanje);
                    }
                    db.SaveChanges();
                }
            }
            else
            {
                return(View("Dodaj", model));
            }


            return(RedirectToAction("Index"));
        }
Example #2
0
        public StatusCodeResult KupiDio(int Id, int kolicina)
        {
            Dio Dio = db.Dio
                      .Include(x => x.DioStanje)
                      .Where(x => x.IsDeleted == false)
                      .Where(x => x.DioId == Id).FirstOrDefault();

            if (Dio == null)
            {
                return(new NotFoundResult());// 404
            }

            if (kolicina < 1)
            {
                return(new BadRequestResult());
            }

            var Klijent = HttpContext.GetLogiraniKorisnik().Klijent;

            var ukupno_u_skladistu = Dio.DioStanje.Count(x => x.Aktivan == true && x.KupacId == null);
            var ukupno_u_kosarici  = db.KorpaStavka.Where(x => x.KlijentId == Klijent.Id && x.DioId == Id).Sum(x => x.Kolicina);

            if (kolicina > ukupno_u_skladistu - ukupno_u_kosarici)
            {
                return(new BadRequestResult()); // 400
            }


            var PostojecaStvaka = db.KorpaStavka.Where(x => x.KlijentId == Klijent.Id && x.DioId == Id).FirstOrDefault();

            if (PostojecaStvaka != null)
            {
                PostojecaStvaka.Kolicina += kolicina;
            }
            else
            {
                db.KorpaStavka.Add(new KorpaStavka
                {
                    KlijentId = Klijent.Id,
                    DioId     = Id,
                    Kolicina  = kolicina
                });
            }
            db.SaveChanges();

            return(new OkResult()); // 200
        }
Example #3
0
        public static void Main(string[] args)
        {
            var audioPath    = @"vaiueo2d.wav";
            var audioOutPath = @"vaiueo2d-out.wav";

            var(x, fs, nbit) = AudioIO.WavRead(audioPath);
            var(f0, t)       = Dio.Compute(x, fs);
            f0 = StoneMask.Compute(x, fs, t, f0);
            var fftSize = CheapTrick.GetFftSize(fs);
            var sp      = CheapTrick.Compute(x, fs, t, f0, fftSize: fftSize);
            var ap      = D4C.Compute(x, fs, t, f0, fftSize: fftSize);

            var ndim = 60;
            var mgc  = Codec.CodeSpectralEnvelope(sp, fs, ndim);
            var bap  = Codec.CodeAperiodicity(ap, fs);

            Console.WriteLine($"{audioPath}:");
            Console.WriteLine($"    input samples count: {x.Length}");
            Console.WriteLine($"    sampling rate: {fs}");
            Console.WriteLine($"    bit rate: {nbit}");
            Console.WriteLine();
            Console.WriteLine($"    frame count: {f0.Length}");
            Console.WriteLine($"    fft size: {fftSize}");
            Console.WriteLine($"    sp width: {sp.GetLength(1)}");
            Console.WriteLine();
            Console.WriteLine($"    mgc width: {ndim}");
            Console.WriteLine($"    bap width: {bap.GetLength(1)}");
            Console.WriteLine();

            for (int i = 0; i < f0.Length; i++)
            {
                f0[i] *= 1.6789;
            }

            sp = Codec.DecodeSpectralEnvelope(mgc, fs, fftSize);
            ap = Codec.DecodeAperiodicity(bap, fs, fftSize);
            var y = Synthesis.Compute(f0, sp, ap, fs);

            Console.WriteLine($"--> {audioOutPath}");
            AudioIO.WavWrite(y, fs, nbit, audioOutPath);
        }
Example #4
0
 public bool addDio(Dio noviDio)
 {
     montiraniDijelovi.Add(noviDio);
     return(true);
 }