public ActionResult Create(tbl_batch batch) { try { // TODO: Add insert logic here if (db.tbl_batch.SingleOrDefault(x => x.batchID == batch.batchID) == null) { db.tbl_batch.Add(batch); db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("batch number is already taken select another", JsonRequestBehavior.AllowGet)); } } catch { return(Json("failure", JsonRequestBehavior.AllowGet)); } }
public void savedlogic() { try { if (CheckDouble(txtBatchName.Text) == "false") { lblcheckDoubleError.Text = String.Empty; tbl_batch bat = new tbl_batch(); bat.branch_id = branchId;//Convert.ToInt32(Session["branch_id"]); bat.company_id = companyId;//Convert.ToInt32(Session["company_id"]); bat.batch_name = txtBatchName.Text; bat.created_by = User_id; //Convert.ToString(Session["UserID"]); bat.created_date = DateTime.Today; bat.modified_by = ""; bat.modified_date = null; bat.status = true; context.tbl_batch.Add(bat); context.SaveChanges(); divalert.Visible = true; lblAlert.Text = "Saved Successfully"; txtBatchName.Text = string.Empty; ((Batch)this.Page).loadDataTable(); } else { divalert.Visible = false; lblcheckDoubleError.ForeColor = System.Drawing.Color.Red; lblcheckDoubleError.Text = "This Batch name already Exists"; return; } } catch (Exception ex) { ErrorLog.saveerror(ex); //Do Logging } }
public ActionResult Edit(int id, tbl_batch batch) { try { // TODO: Add update logic here var oldbatch = db.tbl_batch.SingleOrDefault(x => x.batchID == id); if (oldbatch != null) { oldbatch.batchDescription = batch.batchDescription; db.SaveChanges(); return(Json("success", JsonRequestBehavior.AllowGet)); } else { return(Json("batch not found", JsonRequestBehavior.AllowGet)); } } catch { return(Json("failure", JsonRequestBehavior.AllowGet)); } }