public IActionResult Post([FromBody] LoadDetail LoadDetail) { LoadDetail loadDetail = null; _service.SaveLoadDetail(loadDetail); return(Ok(loadDetail)); }
//Post single truck to the database (called by the Post(movie) method) public void SaveLoadDetail(LoadDetail loadDetail) { if (loadDetail.Id == 0) { _repo.Add(loadDetail); } else { _repo.Update(loadDetail); } }
//Delete single truck form the database(called by the Delete(truck) method) public void DeleteLoadDetail(int id) { LoadDetail loadDetailToDelete = _repo.Query <LoadDetail>().Where(l => l.Id == id).FirstOrDefault(); _repo.Delete(loadDetailToDelete); }
public JsonResult SaveLoadCylinderDetails(int userid, DateTime loadDate, int cylindertype, int nooffilledcylinder, string remark) { string vErroMessage = ""; bool status = true; try { //if (obj.LoadDetail != null) //{ // foreach (var item in obj.LoadDetail) // { var fiiledcount = db.LiveCylinderDetails.Where(ite => ite.cylinder_Id == cylindertype).FirstOrDefault().FilledCylinderCount; if (fiiledcount <= 0) { status = false; vErroMessage = "No Cylinder Available"; } else if (fiiledcount < nooffilledcylinder) { status = false; vErroMessage = "Only " + fiiledcount + " filled cylinder available"; } // } //} //if (db.LiveCylinderDetails.Where(ite => ite.cylinder_Id == cylindertype).FirstOrDefault().FilledCylinderCount <= 0) //{ // status = false; // vErroMessage = "No Cylinder Available"; //} if (status) { LoadCylinder obj = new LoadCylinder(); obj.createdBy = User.Identity.Name; obj.createdOn = System.DateTime.Now; obj.user_id = userid; string vUsername = db.tblusers.Where(obj1 => (obj1.ID == userid)).SingleOrDefault().username; obj.loadDate = loadDate; List <LoadDetail> objdlist = new List <LoadDetail>(); LoadDetail objd = new LoadDetail(); obj.userName = vUsername; objd.FilledCylinder = nooffilledcylinder; objd.cylinder_Id = cylindertype; string cylindertypename = db.CylinderMasters.Where(ite => ite.ID == cylindertype).FirstOrDefault().cylinderType; objd.cylinderType = cylindertypename; objdlist.Add(objd); obj.LoadDetail = objdlist; repo.Insert(obj); vErroMessage = "Record Added Successfully"; status = true; } } catch (Exception ex) { vErroMessage = "Error Occured while your transaction!"; status = false; } return(new JsonResult() { Data = new { status = status, Message = vErroMessage } }); }