public AdditionOrDeduction Insert(AdditionOrDeduction objAdditionOrDeduction) { using (IDbConnection connection = OpenConnection(dataConnection)) { var result = new AdditionOrDeduction(); IDbTransaction trn = connection.BeginTransaction(); string sql = @"INSERT INTO AdditionDeduction (AddDedRefNo,AddDedName,AddDedType,AddDedRemarks,CreatedBy,CreatedDate,OrganizationId,isActive) VALUES(@AddDedRefNo,@AddDedName, @AddDedType, @AddDedRemarks,@CreatedBy,@CreatedDate,@OrganizationId,1); SELECT CAST(SCOPE_IDENTITY() as int)"; try { int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(AdditionOrDeduction).Name, "0", 1); objAdditionOrDeduction.AddDedRefNo = "AD/" + internalid; int id = connection.Query <int>(sql, objAdditionOrDeduction, trn).Single(); objAdditionOrDeduction.AddDedId = id; //connection.Dispose(); trn.Commit(); } catch (Exception ex) { trn.Rollback(); objAdditionOrDeduction.AddDedId = 0; objAdditionOrDeduction.AddDedRefNo = null; } return(objAdditionOrDeduction); } }
public int Delete(AdditionOrDeduction objAdditionOrDeduction) { int result = 0; using (IDbConnection connection = OpenConnection(dataConnection)) { string sql = @" Update AdditionDeduction Set isActive=0 WHERE AddDedId=@AddDedId"; try { var id = connection.Execute(sql, objAdditionOrDeduction); objAdditionOrDeduction.AddDedId = id; result = 0; } catch (SqlException ex) { int err = ex.Errors.Count; if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error { switch (ex.Errors[0].Number) { case 547: // Foreign Key violation result = 1; break; default: result = 2; break; } } } return(result); } }
public ActionResult Create(AdditionOrDeduction model) { model.OrganizationId = OrganizationId; model.CreatedDate = System.DateTime.Now; model.CreatedBy = UserID.ToString(); var repo = new AdditionOrDeductionRepository(); bool isexists = repo.IsFieldExists(repo.ConnectionString(), "AdditionDeduction", "AddDedName", model.AddDedName, null, null); if (!isexists) { var result = new AdditionOrDeductionRepository().Insert(model); if (result.AddDedId > 0) { TempData["Success"] = "Added Successfully!"; TempData["AddDedRefNo"] = result.AddDedRefNo; return(RedirectToAction("Create")); } else { FillAdditionDeduction(); TempData["error"] = "Oops!!..Something Went Wrong!!"; TempData["AddDedRefNo"] = null; return(View("Create", model)); } } else { FillAdditionDeduction(); TempData["error"] = "This Name Alredy Exists!!"; TempData["AddDedRefNo"] = null; return(View("Create", model)); } }
public ActionResult Delete(AdditionOrDeduction model) { int result = new AdditionOrDeductionRepository().Delete(model); if (result == 0) { TempData["Success"] = "Deleted Successfully!"; TempData["AddDedRefNo"] = model.AddDedRefNo; return(RedirectToAction("Create")); } else { if (result == 1) { TempData["error"] = "Sorry!! You Cannot Delete This Addition/Deduction It Is Already In Use"; TempData["AddDedRefNo"] = null; } else { TempData["error"] = "Oops!!..Something Went Wrong!!"; TempData["AddDedRefNo"] = null; } return(RedirectToAction("Create")); } }
public ActionResult Create() { ViewBag.Title = "Create"; AdditionOrDeduction AdditionOrDeduction = new AdditionOrDeduction(); AdditionOrDeduction.AddDedRefNo = new AdditionOrDeductionRepository().GetRefNo(AdditionOrDeduction); FillAdditionDeduction(); return(View(AdditionOrDeduction)); }
public AdditionOrDeduction Update(AdditionOrDeduction objAdditionOrDeduction) { using (IDbConnection connection = OpenConnection(dataConnection)) { string sql = @" Update AdditionDeduction Set AddDedRefNo=@AddDedRefNo,AddDedName=@AddDedName,AddDedType=@AddDedType,AddDedRemarks=@AddDedRemarks OUTPUT INSERTED.AddDedId WHERE AddDedId=@AddDedId"; var id = connection.Execute(sql, objAdditionOrDeduction); return(objAdditionOrDeduction); } }
public string GetRefNo(AdditionOrDeduction objAdditionOrDeduction) { using (IDbConnection connection = OpenConnection(dataConnection)) { string RefNo = ""; var result = new AdditionOrDeduction(); IDbTransaction trn = connection.BeginTransaction(); try { int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(AdditionOrDeduction).Name, "0", 0); RefNo = "AD/" + internalid; trn.Commit(); } catch (Exception ex) { trn.Rollback(); } return(RefNo); } }