예제 #1
0
 public IActionResult PutTblCarTypeToDataBase(int key, [FromBody] TblCarType uCarType)
 {
     if (uCarType != null)
     {
         var hasData = this.repository.UpdateTblCarTypeToDataBase(key, uCarType);
         if (hasData != null)
         {
             return(new JsonResult(hasData, DefaultJsonSettings));
         }
     }
     return(new StatusCodeResult(500));
 }
예제 #2
0
 public IActionResult PostTblCarTypeToDataBase([FromBody] TblCarType nCarType)
 {
     if (nCarType != null)
     {
         var hasData = this.repository.InsertTblCarTypeToDataBase(nCarType);
         if (hasData != null)
         {
             return(new JsonResult(hasData, DefaultJsonSettings));
         }
     }
     return(new StatusCodeResult(500));
 }
예제 #3
0
        public TblCarType InsertTblCarTypeToDataBase(TblCarType nCarType)
        {
            try
            {
                if (nCarType != null)
                {
                    nCarType.CreateDate = this.DateOfServer;
                    nCarType.Creator    = nCarType.Creator ?? "someone";

                    this.Context.TblCarType.Add(nCarType);
                    return(this.Context.SaveChanges() > 0 ? this.GetTblCarTypeWithKey(nCarType.CarTypeId) : null);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Has error {ex.ToString()}");
            }
            return(null);
        }
예제 #4
0
        public TblCarType UpdateTblCarTypeToDataBase(int CarTypeID, TblCarType uCarType)
        {
            try
            {
                var dbCarType = this.Context.TblCarType.Find(CarTypeID);
                if (dbCarType != null)
                {
                    uCarType.CreateDate = dbCarType.CreateDate;
                    uCarType.ModifyDate = this.DateOfServer;
                    uCarType.Modifyer   = uCarType.Modifyer ?? "someone";

                    this.Context.Entry(dbCarType).CurrentValues.SetValues(uCarType);
                    return(this.Context.SaveChanges() > 0 ? this.GetTblCarTypeWithKey(CarTypeID) : null);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Has error {ex.ToString()}");
            }
            return(null);
        }