Example #1
0
        public bool Save(EmployeeDto employeeDto)
        {
            Employee employee = new Employee
            {
                FirstName   = employeeDto.FirstName,
                LastName    = employeeDto.LastName,
                PhoneNumber = employeeDto.PhoneNumber,
                Email       = employeeDto.Email,
                BirthDate   = employeeDto.BirthDate,
                Position    = employeeDto.Position,
                Salary      = employeeDto.Salary
            };

            try
            {
                using (CompanyRepo repo = new CompanyRepo())
                {
                    repo.EmployeeRepository.Insert(employee);
                    repo.Save();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        public bool Save(ManagerDto managerDto)
        {
            Manager manager = new Manager
            {
                FirstName   = managerDto.FirstName,
                LastName    = managerDto.LastName,
                PhoneNumber = managerDto.PhoneNumber,
                Email       = managerDto.Email,
                BirthDate   = managerDto.BirthDate,
                Nationality = managerDto.Nationality,
                Salary      = managerDto.Salary
            };

            try
            {
                using (CompanyRepo repo = new CompanyRepo())
                {
                    repo.ManagerRepository.Insert(manager);
                    repo.Save();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #3
0
 public bool Save(ProjectEmployeeDto projectEmployeeDto)
 {
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             try
             {
                 var pe = new ProjectEmployee()
                 {
                     id_project  = projectEmployeeDto.id_project,
                     project     = repo.ProjectRepository.GetByID(projectEmployeeDto.projectDto.Id),
                     id_employee = projectEmployeeDto.id_employee,
                     empployee   = repo.EmployeeRepository.GetByID(projectEmployeeDto.employeeDto.Id)
                 };
                 repo.ProjectEmployeeRepository.Insert(pe);
                 repo.Save();
                 return(true);
             }
             catch
             {
                 return(false);
             }
         }
         return(true);
     }
     catch
     {
         return(true);
     }
 }
Example #4
0
 public void Save(Company company)
 {
     try
     {
         _repo.Save(company);
     }
     catch (Exception ex)
     {
         _logger.Error("Error during CompanyService.Save()", ex);
         throw;
     }
 }
Example #5
0
 public bool Delete(int id)
 {
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             Project project = repo.ProjectRepository.GetByID(id);
             repo.ProjectRepository.Delete(project);
             repo.Save();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #6
0
 public bool Delete(int id)
 {
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             Employee employee = repo.EmployeeRepository.GetByID(id);
             repo.EmployeeRepository.Delete(employee);
             repo.Save();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #7
0
 public bool Delete(int id)
 {
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             Manager manager = repo.ManagerRepository.GetByID(id);
             repo.ManagerRepository.Delete(manager);
             repo.Save();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public ActionResult Save(客戶資料 model)
        {
            var msg = "客戶資料" + (model.Id == 0 ? "新增" : "更新") + "成功";

            if (ModelState.IsValid)
            {
                try
                {
                    CompanyRepo.Save(model);
                    CompanyRepo.UnitOfWork.Commit();
                    return(Json(new { id = model.Id, isValid = true, message = HttpUtility.HtmlEncode(msg) }));
                }
                catch (Exception ex)
                {
                    return(Json(new { isValid = false, message = HttpUtility.HtmlEncode("客戶資料儲存失敗。錯誤訊息: " + ex.Message) }));
                }
            }
            msg = string.Join(" ", ModelState.Values.SelectMany(p => p.Errors).Select(p => p.ErrorMessage));
            return(Json(new { isValid = false, message = HttpUtility.HtmlEncode("客戶資料儲存時,驗證欄位失敗。" + msg) }));
        }
Example #9
0
 public bool Update(ProjectEmployeeDto projectEmployeeDto)
 {
     using (CompanyRepo repo = new CompanyRepo())
     {
         try
         {
             var result = repo.ProjectEmployeeRepository.GetByID(projectEmployeeDto.Id);
             if (result == null)
             {
                 return(false);
             }
             result.Id          = projectEmployeeDto.Id;
             result.id_project  = projectEmployeeDto.id_project;
             result.id_employee = projectEmployeeDto.id_employee;
             repo.ProjectEmployeeRepository.Update(result);
             repo.Save();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Example #10
0
        public bool Update(ProjectDto projectDto)
        {
            /*if(projectDto.managerDto == null || projectDto.managerDto.Id == 0)
             * {
             *  return false;
             * }
             *
             * Project project = new Project
             * {
             *  Id = projectDto.Id,
             *  Name = projectDto.Name,
             *  Description = projectDto.Description,
             *  Created = projectDto.Created,
             *  Client = projectDto.Client,
             *  Price = projectDto.Price,
             *  Manager_Id = projectDto.managerDto.Id
             * };
             *
             * try
             * {
             *  using (CompanyRepo repo = new CompanyRepo())
             *  {
             *      Manager manager = repo.ManagerRepository.GetByID(project.Manager_Id);
             *      if(manager != null)
             *      {
             *          project.manager = manager;
             *          repo.ProjectRepository.Update(project);
             *          repo.Save();
             *          return true;
             *      }
             *      return false;
             *  }
             * }
             * catch
             * {
             *  return false;
             * }*/



            using (CompanyRepo repo = new CompanyRepo())
            {
                try
                {
                    var result = repo.ProjectRepository.GetByID(projectDto.Id);
                    if (result == null)
                    {
                        return(false);
                    }
                    result.Id          = projectDto.Id;
                    result.Name        = projectDto.Name;
                    result.Description = projectDto.Description;
                    result.Created     = projectDto.Created;
                    result.Client      = projectDto.Client;
                    result.Price       = projectDto.Price;
                    result.Manager_Id  = projectDto.managerId;
                    repo.ProjectRepository.Update(result);
                    repo.Save();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Example #11
0
 public bool Save(ProjectDto projectDto)
 {
     /* if(projectDto.managerDto == null || projectDto.managerDto.Id == 0)
      * {
      *   return false;
      * }
      *
      * Manager manager = new Manager
      * {
      *   FirstName = projectDto.managerDto.FirstName,
      *   LastName = projectDto.managerDto.LastName,
      *   PhoneNumber = projectDto.managerDto.PhoneNumber,
      *   Email = projectDto.managerDto.Email,
      *   BirthDate = projectDto.managerDto.BirthDate,
      *   Nationality = projectDto.managerDto.Nationality,
      *   Salary = projectDto.managerDto.Salary
      * };
      *
      * Project project = new Project
      * {
      *   Name = projectDto.Name,
      *   Description = projectDto.Description,
      *   Created = projectDto.Created,
      *   Client = projectDto.Client,
      *   Price = projectDto.Price,
      *   Manager_Id = projectDto.managerDto.Id,
      *   manager = manager
      *
      * };
      *
      * try
      * {
      *   using (CompanyRepo repo = new CompanyRepo())
      *   {
      *       Manager manager1 = repo.ManagerRepository.GetByID(project.Manager_Id);
      *       if(manager1 != null)
      *       {
      *           project.manager = manager1;
      *           repo.ProjectRepository.Insert(project);
      *           repo.Save();
      *           return true;
      *       }
      *       return false;
      *   }
      * }
      * catch
      * {
      *   Console.WriteLine(project);
      *   return false;
      * }*/
     try
     {
         using (CompanyRepo repo = new CompanyRepo())
         {
             try
             {
                 var project = new Project()
                 {
                     Name        = projectDto.Name,
                     Description = projectDto.Description,
                     Created     = projectDto.Created,
                     Client      = projectDto.Client,
                     Price       = projectDto.Price,
                     Manager_Id  = projectDto.managerId,
                     manager     = repo.ManagerRepository.GetByID(projectDto.managerId),
                     CreatedOn   = DateTime.Now
                 };
                 repo.ProjectRepository.Insert(project);
                 repo.Save();
                 return(true);
             }
             catch
             {
                 return(false);
             }
         }
         return(true);
     }
     catch
     {
         return(true);
     }
 }