public JsonResult Create(LoadCylinder obj) { bool status = true; string vMessage = ""; try { if (ModelState.IsValid) { if (obj.LoadDetail != null) { foreach (var item in obj.LoadDetail) { var fiiledcount = db.LiveCylinderDetails.Where(ite => ite.cylinder_Id == item.cylinder_Id).FirstOrDefault().FilledCylinderCount; if (fiiledcount <= 0) { status = false; vMessage = "No Cylinder Available for " + item.cylinderType; break; } else if (fiiledcount < item.FilledCylinder) { status = false; vMessage = "Only " + fiiledcount + " filled cylinder available for " + item.cylinderType; break; } } } if (status) { obj.createdBy = Convert.ToString(Session["UserName"]); obj.createdOn = System.DateTime.Now; obj.users = repo.GetAllUsers(); if (obj.LoadDetail != null) { repo.Insert(obj); } vMessage = "Record Added Successfully"; status = true; } } else { vMessage = "Please fill manadatory fields"; status = false; } } catch (Exception ex) { vMessage = "Sorry Some Problem Occured"; } return(new JsonResult { Data = new { status = status, Message = vMessage } }); }
private void btnInsert_Click(object sender, EventArgs e) { if (cmbBeam.SelectedIndex == -1) { MessageBox.Show("Kiriş tipi seçiniz."); return; } if (txtName.Text == String.Empty) { MessageBox.Show("Yük tipi adını boş geçemezsiniz."); return; } try { using (ILoadRepository loadRepo = new LoadRepository(new Datacore.Data.BeamDeflectionDbContext())) { Load load = new Load { BeamId = ((Beam)cmbBeam.SelectedItem).ID, Name = txtName.Text }; var result = loadRepo.Insert(load); switch (result.State) { case Basecore.Model.Enums.BusinessResultType.NotSet: lblMessage.Text = result.Message; break; case Basecore.Model.Enums.BusinessResultType.Success: lblMessage.Text = "Kayıt başarılı. Son kaydedilen yük tipinin adı : " + result.Result.Name; txtName.Text = String.Empty; txtName.Focus(); break; case Basecore.Model.Enums.BusinessResultType.Error: lblMessage.Text = result.Message; break; case Basecore.Model.Enums.BusinessResultType.Warning: lblMessage.Text = result.Message; break; case Basecore.Model.Enums.BusinessResultType.Info: lblMessage.Text = result.Message; break; default: break; } } } catch (Exception ex) { lblMessage.Text = "Hata : " + ex.GetBaseException(); } }
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 } }); }