public async Task <bool> UpdateData(string id, Ordersampletbl obj)
        {
            try
            {
                if (id != obj.NoBalittanah)
                {
                    return(false);
                }

                using (var context = new smlpobDB())
                {
                    context.Ordersampletbl.Attach(obj);
                    context.Entry(obj).Property(x => x.OrderNo).IsModified           = true;
                    context.Entry(obj).Property(x => x.SampleCode).IsModified        = true;
                    context.Entry(obj).Property(x => x.CountNumber).IsModified       = true;
                    context.Entry(obj).Property(x => x.SampleDescription).IsModified = true;
                    context.Entry(obj).Property(x => x.SamplingDate).IsModified      = true;
                    context.Entry(obj).Property(x => x.Village).IsModified           = true;
                    context.Entry(obj).Property(x => x.SubDistrict).IsModified       = true;
                    context.Entry(obj).Property(x => x.District).IsModified          = true;
                    context.Entry(obj).Property(x => x.Province).IsModified          = true;
                    context.Entry(obj).Property(x => x.Longitude).IsModified         = true;
                    context.Entry(obj).Property(x => x.Latitude).IsModified          = true;
                    context.Entry(obj).Property(x => x.LandUse).IsModified           = true;
                    context.Entry(obj).Property(x => x.IsReceived).IsModified        = true;
                    context.Entry(obj).Property(x => x.ModBy).IsModified             = true;
                    context.Entry(obj).Property(x => x.ModDate).IsModified           = true;
                    await context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = "";
                LogHelpers.WriteLog();
            }

            return(false);
        }
        public async Task <bool> AddData(Ordersampletbl obj)
        {
            try
            {
                using (var context = new smlpobDB())
                {
                    context.Ordersampletbl.Add(obj);
                    await context.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = "";
                LogHelpers.WriteLog();
            }

            return(false);
        }
        public string AutoGenerateSample(string komoditas, string analisis)
        {
            try
            {
                int    no   = int.Parse(komoditas);
                string cmdt = "";
                using (var context = new smlpobDB())
                {
                    var kmd = (from x in context.Comoditytbl
                               where x.ComodityNo == no
                               select x.ComodityName).AsNoTracking().SingleOrDefault();
                    cmdt = kmd;
                }

                string id            = "";
                string kodeKomoditas = "";
                string kodeAnalisis  = "";

                // kode komoditas
                if (cmdt.Contains("Pupuk Organik"))
                {
                    kodeKomoditas = "Po.";
                }
                else if (cmdt.Contains("Pupuk Anorganik"))
                {
                    kodeKomoditas = "Pa.";
                }
                else if (cmdt.Contains("Tanah"))
                {
                    kodeKomoditas = "Th.";
                }
                else if (cmdt.Contains("Air"))
                {
                    kodeKomoditas = "A.";
                }
                else if (cmdt.Contains("Tanaman"))
                {
                    kodeKomoditas = "Tn.";
                }

                // kode analisis
                if (analisis.Contains("Kimia"))
                {
                    kodeAnalisis = "K.";
                }
                else if (analisis.Contains("Biologi"))
                {
                    kodeAnalisis = "B.";
                }
                else if (analisis.Contains("Fisika"))
                {
                    kodeAnalisis = "F.";
                }

                using (var context = new smlpobDB())
                {
                    var data = (from x in context.Ordersampletbl
                                .OrderByDescending(x => x.NoBalittanah)
                                where x.NoBalittanah.Contains(kodeKomoditas) &&
                                x.NoBalittanah.Contains(kodeAnalisis)
                                select x.NoBalittanah).AsNoTracking().SingleOrDefault();

                    if (data != null)
                    {
                        string[] strSplit   = data.Split('.');
                        int      noUrut1    = int.Parse(strSplit[2]);
                        int      noUrut2    = int.Parse(strSplit[5]);
                        string   newNoUrut1 = (noUrut1 + 1).ToString();
                        string   newNoUrut2 = (noUrut2 + 1).ToString();

                        id = DatetimeHelper.GetYearNow() + "." + DatetimeHelper.GetMonthNow() + "." + newNoUrut1 +
                             "." + kodeAnalisis + kodeKomoditas + newNoUrut2;
                    }
                    else
                    {
                        id = DatetimeHelper.GetYearNow() + "." + DatetimeHelper.GetMonthNow() + "." + "1" +
                             "." + kodeAnalisis + kodeKomoditas + "1";
                    }

                    var sample = new Ordersampletbl
                    {
                        NoBalittanah = id,
                        SampleCode   = "",
                    };

                    context.Ordersampletbl.Add(sample);
                    context.SaveChangesAsync();

                    return(id);
                }
            }
            catch (Exception ex)
            {
                LogHelpers.source  = this.GetType().Name;
                LogHelpers.message = ex.Message;
                LogHelpers.user    = currentUser;
                LogHelpers.WriteLog();
            }

            return(null);
        }