Example #1
0
        public async Task <IActionResult> AddPost([FromBody] Warna model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var postId = await facade.AddPost(model);

                    if (postId > 0)
                    {
                        return(Ok(postId));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception)
                {
                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Example #2
0
    public void GeneratingQuestion()
    {
        soalText.text = level [currentLevel].warna[currentPhase].ToString();
        DatabaseSuara.instance.PlaySuara(level [currentLevel].warna[currentPhase]);
        jawaban = level [currentLevel].warna [currentPhase];

        buahLoaded.Clear();
        for (int i = 0; i < buahPilihan.Length; i++)
        {
            Buah buah = DatabaseBuah.Instance.GetRandomBuah();

            // Biar gak ada buah yang sama
            while (buahLoaded.Exists(x => x.nama == buah.nama))
            {
                buah = DatabaseBuah.Instance.GetRandomBuah();
            }

            // Biar gak ada dua jawaban
            if (buahLoaded.Exists(x => x.warna == jawaban))
            {
                while (buah.warna == jawaban)
                {
                    buah = DatabaseBuah.Instance.GetRandomBuah();
                }
            }

            buahLoaded.Add(buah);
            buahPilihan [i].GetComponent <TombolBuah> ().buah = buah;
            buahPilihan [i].GetComponent <Image> ().sprite    = buah.sprite;
        }

        // Generate ulang apabila tidak ada jawaban yang benar
        if (!buahLoaded.Exists(x => x.warna == jawaban))
        {
            GeneratingQuestion();
        }



        /*if (GameManager.Instance.level == 1) {
         *      soalText.text = namaWarnaLevel1 [0];
         * }
         * else if (GameManager.Instance.level == 2) {
         *      soalText.text = namaWarnaLevel2 [0];
         * }
         * else if (GameManager.Instance.level == 3) {
         *      soalText.text = namaWarnaLevel3 [0];
         * }
         * else if (GameManager.Instance.level == 4) {
         *      soalText.text = namaWarnaLevel4 [0];
         * }
         * else if (GameManager.Instance.level == 5) {
         *      soalText.text = namaWarnaLevel5 [0];
         * }
         * else {
         *      soalText.text = "sasa";
         * }*/
    }
Example #3
0
 public void PlaySuara(Warna warna)
 {
     foreach (SuaraWarna suara in suaraWarna)
     {
         if (suara.warna == warna)
         {
             GetComponent <AudioSource> ().clip = suara.clip;
             GetComponent <AudioSource> ().Play();
         }
     }
 }
Example #4
0
        public async Task <long> AddPost(Warna model)
        {
            var postId = await dep.AddPost(model);

            if (postId > 0)
            {
                return(postId);
            }
            else
            {
                return(0);
            }
        }
Example #5
0
        public async Task <long> Add(Warna model)
        {
            if (db != null)
            {
                await db.Warna.AddAsync(model);

                await db.SaveChangesAsync();

                return(model.Id);
            }

            return(0);
        }
Example #6
0
        public async Task <long> AddPost(Warna warna)
        {
            if (db != null)
            {
                await db.Warna.AddAsync(warna);

                await db.SaveChangesAsync();

                return(warna.Id);
            }

            return(0);
        }
Example #7
0
        public async Task <bool> UpdatePost(Warna warna)
        {
            bool result = false;

            if (db != null)
            {
                //Delete that warna
                db.Warna.Update(warna);

                //Commit the transaction
                await db.SaveChangesAsync();

                result = true;
            }
            return(result);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            for (int row = 0; row < dataGridView1.Rows.Count; row++)
            {
                if (dataGridView1.Rows[row].Cells[0].Value != null &&
                    dataGridView1.Rows[row].Cells[0].Value.Equals(textBox1.Text))
                {
                    MessageBox.Show("Maaf ! Duplicate Data");
                    return;
                }
            }/*end for*/

            if (textBox1.Text == "")
            {
                MessageBox.Show("------MOHON MENGISIKAN DATA-------");
            }
            else
            {
                Warna itemWarna = new Warna();
                itemWarna.Jenis = textBox1.Text;
                DaftarWarna.Add(itemWarna);
                dataGridView1.Rows.Add(textBox1.Text);
            } /*end if */
        }
Example #9
0
        public async Task <IActionResult> UpdatePost([FromBody] Warna model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await facade.UpdatePost(model);

                    return(Ok());
                }
                catch (Exception ex)
                {
                    if (ex.GetType().FullName ==
                        "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException")
                    {
                        return(NotFound());
                    }

                    return(BadRequest());
                }
            }

            return(BadRequest());
        }
Example #10
0
        public async Task <BarangResponse> SubmitUpload(string fileName, string username)
        {
            BarangResponse response = new BarangResponse();

            try
            {
                string    folderName = Path.Combine("Resources", "UploadDocs");
                string    filePath   = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                string    sheetName  = "Master";
                DataTable dt         = new DataTable();

                string dbPath = Path.Combine(folderName, fileName);

                List <Kota> ListKota = await da_kota.GetAll();

                List <Merk> ListMerk = await da_merk.GetAllMerk();

                List <ModelBarang> ListModel = await da_model.GetAllModel();

                List <TypeBarang> ListType = await da_type.GetAllType();

                List <Warna> ListWarna = await da_warna.GetWarna();

                List <Barang> ListBarang = await dep.GetAllBarang();

                using (ExcelPackage pck = new ExcelPackage())
                {
                    using (FileStream stream = new FileStream(dbPath, FileMode.Open))
                    {
                        pck.Load(stream);
                        ExcelWorksheet oSheet = pck.Workbook.Worksheets[sheetName];
                        dt = WorksheetToDataTable(oSheet);
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            long KotaID       = 0;
                            long MerkID       = 0;
                            long ModelID      = 0;
                            long TypeID       = 0;
                            long WarnaID      = 0;
                            long BarangID     = 0;
                            long NegoBarangID = 0;

                            errMerk       = dt.Rows[i].ItemArray.GetValue(1).ToString();
                            errModel      = dt.Rows[i].ItemArray.GetValue(2).ToString();
                            errType       = dt.Rows[i].ItemArray.GetValue(3).ToString();
                            errWarna      = dt.Rows[i].ItemArray.GetValue(4).ToString();
                            errBarang     = dt.Rows[i].ItemArray.GetValue(5).ToString();
                            errOTR        = dt.Rows[i].ItemArray.GetValue(6).ToString();
                            errHargaFinal = dt.Rows[i].ItemArray.GetValue(8).ToString();

                            #region Insert To Kota
                            string Kota = dt.Rows[i].ItemArray.GetValue(0).ToString();
                            if (!ListKota.Where(x => x.Name.ToLower() == Kota.ToLower()).Any())
                            {
                                Kota k = new Kota();
                                k.Name        = Kota;
                                k.Description = Kota;

                                k.RowStatus = true;
                                k.Created   = DateTime.Now;
                                k.CreatedBy = username;
                                KotaID      = da_kota.AddPost(k).Result;
                                ListKota.Add(k);
                            }
                            else
                            {
                                KotaID = ListKota.Where(x => x.Name.ToLower() == Kota.ToLower() && x.RowStatus == true).First().Id;
                            }
                            #endregion

                            #region Insert To Merk
                            string Merk = dt.Rows[i].ItemArray.GetValue(1).ToString();
                            if (!ListMerk.Where(x => x.Name.ToLower() == Merk.ToLower()).Any())
                            {
                                Merk m = new Merk();
                                m.Name        = Merk;
                                m.Description = Merk;
                                m.RowStatus   = true;
                                m.Created     = DateTime.Now;
                                m.CreatedBy   = username;
                                MerkID        = da_merk.Add(m).Result;
                                ListMerk.Add(m);
                            }
                            else
                            {
                                MerkID = ListMerk.Where(x => x.Name.ToLower() == Merk.ToLower() && x.RowStatus == true).First().Id;
                            }
                            #endregion

                            #region Insert to ModelBarang
                            string Model = dt.Rows[i].ItemArray.GetValue(2).ToString();
                            if (!ListModel.Where(x => x.Name.ToLower() == Model.ToLower()).Any())
                            {
                                ModelBarang mb = new ModelBarang();
                                mb.MerkId      = MerkID;
                                mb.Name        = Model;
                                mb.Description = Model;
                                mb.RowStatus   = true;
                                mb.Created     = DateTime.Now;
                                mb.Createdby   = username;
                                ModelID        = da_model.Add(mb).Result;
                                ListModel.Add(mb);
                            }
                            else
                            {
                                ModelID = ListModel.Where(x => x.Name.ToLower() == Model.ToLower() && x.RowStatus == true).First().Id;
                            }
                            #endregion

                            #region Insert to TypeBarang
                            string Type = dt.Rows[i].ItemArray.GetValue(4).ToString();
                            if (!ListType.Where(x => x.Name.ToLower() == Type.ToLower()).Any())
                            {
                                TypeBarang tb = new TypeBarang();
                                tb.Name          = Type;
                                tb.ModelBarangId = ModelID;
                                tb.Description   = Type;
                                tb.RowStatus     = true;
                                tb.Created       = DateTime.Now;
                                tb.CreatedBy     = username;
                                TypeID           = da_type.Add(tb).Result;
                                ListType.Add(tb);
                            }
                            else
                            {
                                TypeID = ListType.Where(x => x.RowStatus == true && x.Name.ToLower() == Type.ToLower()).First().Id;
                            }
                            #endregion

                            #region Insert to Warna
                            string Warna = dt.Rows[i].ItemArray.GetValue(6).ToString();
                            if (!ListWarna.Where(x => x.Name.ToLower() == Warna.ToLower()).Any())
                            {
                                Warna w = new Warna();
                                w.Name        = Warna;
                                w.Description = Warna;
                                w.Sapcode     = dt.Rows[i].ItemArray.GetValue(5).ToString();
                                w.RowStatus   = true;
                                w.Created     = DateTime.Now;
                                w.CreatedBy   = username;
                                WarnaID       = da_warna.Add(w).Result;
                                ListWarna.Add(w);
                            }
                            else
                            {
                                WarnaID = ListWarna.Where(x => x.RowStatus == true && x.Name.ToLower() == Warna.ToLower()).First().Id;
                            }
                            #endregion

                            string OTRstrRaw = dt.Rows[i].ItemArray.GetValue(8).ToString();
                            string OTRstr    = OTRstrRaw.Contains('.') ? OTRstrRaw.Substring(0, OTRstrRaw.LastIndexOf('.')) : OTRstrRaw;

                            string DiscstrRaw = dt.Rows[i].ItemArray.GetValue(9).ToString();
                            string Discstr    = DiscstrRaw.Contains('.') ? DiscstrRaw.Substring(0, DiscstrRaw.LastIndexOf('.')) : DiscstrRaw;

                            string FinalRaw = dt.Rows[i].ItemArray.GetValue(10).ToString();
                            string Finalstr = FinalRaw.Contains('.') ? FinalRaw.Substring(0, FinalRaw.LastIndexOf('.')) : FinalRaw;

                            string YearstrRaw = dt.Rows[i].ItemArray.GetValue(7).ToString();
                            string Yearstr    = YearstrRaw.Contains('.') ? YearstrRaw.Substring(0, OTRstrRaw.LastIndexOf('.')) : YearstrRaw;

                            long OTR        = Convert.ToInt64(OTRstr);
                            long Discount   = Convert.ToInt64(Discstr);
                            long HargaFinal = Convert.ToInt64(Finalstr);
                            int  Year       = Convert.ToInt32(Yearstr);

                            #region Insert to Barang
                            Barang brg = new Barang()
                            {
                                RowStatus    = true,
                                Created      = DateTime.Now,
                                CreatedBy    = username,
                                HargaOtr     = OTR,
                                Name         = Type,
                                WarnaId      = WarnaID,
                                TypeBarangId = TypeID,
                                KotaId       = KotaID,
                                Year         = Year,
                                KodeType     = dt.Rows[i].ItemArray.GetValue(3).ToString()
                            };
                            BarangID = dep.AddPost(brg).Result;
                            #endregion

                            #region Insert to NegoBarang
                            NegoBarang nb = new NegoBarang()
                            {
                                RowStatus     = true,
                                BarangId      = BarangID,
                                UserProfileId = 3,
                                TypePenawaran = "ask",
                                Harga         = HargaFinal,
                                Created       = DateTime.Now,
                                CreatedBy     = username
                            };
                            NegoBarangID = da_nego.AddPost(nb).Result;
                            #endregion
                        }
                        response.IsSuccess = true;
                        response.Message   = "Success";
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                string Ket = string.Format("Merk={0}, Model={1}, Type={2}, Warna={3}, Barang={4}, HargaOTR={5}, Harga Final={6}, Error={7} ",
                                           errMerk, errModel, errType, errWarna, errBarang, errOTR, errHargaFinal, ex.ToString());
                response.Message   = Ket;// ex.ToString();
                response.IsSuccess = false;
            }
            return(response);
        }
Example #11
0
        public async Task <bool> UpdatePost(Warna model)
        {
            bool result = await dep.UpdatePost(model);

            return(result);
        }