Exemple #1
0
 public static bool Update(Branch branch)
 {
     try
     {
         return BranchDL.Update(branch);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
 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;
     }
 }
Exemple #3
0
        public static bool BranchExists(Branch branch)
        {
            try
            {
                var existingBranch = new Branch();
                using (var context = new PrinterMonitorDBEntities())
                {
                    existingBranch = context.Branches
                                    .Include(b => b.Printers)
                                    .Include(b => b.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;
            }
        }
Exemple #4
0
 public static bool Save(Branch branch)
 {
     try
     {
         using (var context = new PrinterMonitorDBEntities())
         {
             context.Branches.Add(branch);
             context.SaveChanges();
         }
         return true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #5
0
        public static bool Update(Branch branch)
        {
            try
            {
                Branch existingBranch = new Branch();
                using (var context = new PrinterMonitorDBEntities())
                {
                    existingBranch = context.Branches
                                    .Include(b => b.Printers)
                                    .Include(b => b.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 PrinterMonitorDBEntities())
                    {
                        context.Entry(existingBranch).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }