public static bool Update(Branch branch) { try { return BranchDL.Update(branch); } catch (Exception ex) { throw ex; } }
public static bool Save(Branch branch) { try { using (var context = new KioskWebDBEntities()) { context.Branches.Add(branch); context.SaveChanges(); } return true; } catch (Exception ex) { throw ex; } }
public static bool Save(Branch branch, out string message) { try { if (BranchDL.BranchExists(branch)) { message = string.Format("Branch with name: {0} or code: {1} exists already", branch.Name, branch.Code); return false; } else { message = string.Empty; return BranchDL.Save(branch); } } catch (Exception ex) { throw ex; } }
public static bool BranchExists(Branch branch) { try { var existingBranch = new Branch(); using (var context = new KioskWebDBEntities()) { existingBranch = context.Branches .Include("Users") .Where(t => t.Name.Equals(branch.Name) || t.Code.Equals(branch.Code)) .FirstOrDefault(); } if (existingBranch == null) return false; else return true; } catch (Exception ex) { throw ex; } }
public static bool Update(Branch branch) { try { Branch existingBranch = new Branch(); using (var context = new KioskWebDBEntities()) { existingBranch = context.Branches .Include("Users") .Where(t => t.ID == branch.ID) .FirstOrDefault(); } if (existingBranch != null) { existingBranch.Name = branch.Name; existingBranch.Code = branch.Code; existingBranch.Address = branch.Address; using (var context = new KioskWebDBEntities()) { context.Entry(existingBranch).State = EntityState.Modified; context.SaveChanges(); } return true; } else { return false; } } catch (Exception ex) { throw ex; } }