private void AddUnit()
        {
            int C = 0;

            if (Check_Save())
            {
                return;
            }
            try
            {
                dgvData.EndEdit();
                using (DataClasses1DataContext db = new DataClasses1DataContext())
                {
                    foreach (var g in dgvData.Rows)
                    {
                        if (g.IsVisible.Equals(false))
                        {
                            var dd = (from ix in db.tb_Locations
                                      where ix.id == Convert.ToInt16(g.Cells["id"].Value)
                                      select ix).ToList();
                            if (dd.Count > 0)
                            {
                                dbClss.AddHistory(this.Name, "ลบ", "ลบสถานที่เก็บ [" + dd.FirstOrDefault().Location + "]", "");

                                db.tb_Locations.DeleteAllOnSubmit(dd);
                                db.SubmitChanges();
                                C += 1;
                            }
                        }
                    }
                    foreach (var g in dgvData.Rows)
                    {
                        if (g.IsVisible)
                        {
                            if (Convert.ToBoolean(g.Cells["dgvC"].Value))
                            {
                                if (Convert.ToInt16(g.Cells["id"].Value) <= 0)
                                {
                                    var a = (from ix in db.tb_Locations
                                             where ix.Location.ToUpper() == Convert.ToString(g.Cells["Location"].Value).Trim().ToUpper()
                                             select ix).ToList();
                                    if (a.Count() <= 0)
                                    {
                                        tb_Location gy = new tb_Location();
                                        gy.Location   = Convert.ToString(g.Cells["Location"].Value).Trim();
                                        gy.CreateDate = DateTime.Now;
                                        gy.CreateBy   = ClassLib.Classlib.User;
                                        gy.Active     = Convert.ToBoolean(g.Cells["Active"].Value);
                                        gy.Status     = "Completed";

                                        db.tb_Locations.InsertOnSubmit(gy);
                                        db.SubmitChanges();
                                        dbClss.AddHistory(this.Name, "เพิ่มสถานที่เก็บ", "เพิ่มสถานที่เก็บ [" + gy.Location + " Status : " + gy.Active.ToString() + "]", "");
                                        C += 1;
                                    }
                                }
                                else
                                {
                                    var a = (from ix in db.tb_Locations
                                             where ix.id == Convert.ToInt16(g.Cells["id"].Value)
                                             select ix).ToList();
                                    if (a.Count > 0)
                                    {
                                        var unit1 = (from ix in db.tb_Locations
                                                     where ix.id == Convert.ToInt16(g.Cells["id"].Value)
                                                     select ix).First();
                                        unit1.Location   = Convert.ToString(g.Cells["Location"].Value).Trim();
                                        unit1.Active     = Convert.ToBoolean(g.Cells["Active"].Value);
                                        unit1.CreateDate = DateTime.Now;
                                        unit1.CreateBy   = ClassLib.Classlib.User;

                                        C += 1;

                                        db.SubmitChanges();
                                        dbClss.AddHistory(this.Name, "แก้ไข", "แก้ไขสถานที่เก็บ [" + unit1.Location + " Status : " + unit1.Active.ToString() + "]", "");
                                    }
                                }
                            }
                        }
                        //else //Delete
                        //{

                        //    var dd = (from ix in db.tb_Departments
                        //             where ix.id == Convert.ToInt16(g.Cells["id"].Value)
                        //             select ix).ToList();
                        //    if (dd.Count > 0)
                        //    {

                        //        dbClss.AddHistory(this.Name, "ลบ", "ลบแผนก [" + dd.FirstOrDefault().Department + "]", "");

                        //        db.tb_Departments.DeleteAllOnSubmit(dd);
                        //        db.SubmitChanges();
                        //    }
                        //}
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message);
                                   dbClss.AddError(this.Name, ex.Message, this.Name); }

            if (C > 0)
            {
                MessageBox.Show("บันทึกสำเร็จ!");

                DataLoad();
                ViewClick();
            }
        }
        public IHttpActionResult AddNewLocation([FromBody]  AddNewLocationModel model)
        {
            AmigoWallEntities db = new AmigoWallEntities();
            var location = new tb_Location
            {
                Id = Guid.NewGuid().ToString(),
                AddTime = UtilityHelper.getNow(),
                Latitude = model.latitude,
                longitude = model.longtitude,
                LocationName = model.LocationName,
                FullAddress = model.AddressName,
                Status = 0,
                UserId = db.AspNetUsers.Single(u => u.UserName == User.Identity.Name).Id
            };
            db.tb_Location.Add(location);
            db.SaveChanges();
            return Json(new
            {
                Code = 10000,
                Detail = new
                {

                }

            });
        }