public int Save(DepartmentResponsibleDTO obj, string currentUserId) { DepartmentResponsible departmentResponsible; try { _unitOfWork.BeginTransaction(); if (obj.Id == 0) { departmentResponsible = new DepartmentResponsible(); Mapper.Map <DepartmentResponsibleDTO, DepartmentResponsible>(obj, departmentResponsible); departmentResponsible.CreateDate = DateTime.Now; departmentResponsible.CreatedBy = currentUserId; base.Insert(departmentResponsible); } else { departmentResponsible = _repository.Find(obj.Id); Mapper.Map <DepartmentResponsibleDTO, DepartmentResponsible>(obj, departmentResponsible); departmentResponsible.LastUpdateDate = DateTime.Now; departmentResponsible.LastUpdateBy = currentUserId; base.Update(departmentResponsible); } _unitOfWork.SaveChanges(); _unitOfWork.Commit(); return(departmentResponsible.Id); } catch (Exception) { throw; } }
public DepartmentResponsibleDTO GetById(int departmentResponsibleId) { try { DepartmentResponsibleDTO departmentResponsible = new DepartmentResponsibleDTO(); Mapper.Map <DepartmentResponsible, DepartmentResponsibleDTO>(_repository .Query() .Include(c => c.Department) .SelectQueryable() .Where(c => c.Id == departmentResponsibleId).FirstOrDefault(), departmentResponsible); return(departmentResponsible); } catch (Exception ex) { throw ex; } }