public ResponseDto <User> UpdateUser(User User) { var response = new ResponseDto <User>(StatusCode.Successful); using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repo = unitOfWork.GetGenericRepository <User>(); var repositoryTeam = unitOfWork.GetGenericRepository <Team>(); IQueryable <User> users = repo.GetAll(); response.Data = users.FirstOrDefault(x => x.UserId == User.UserId); if (response.Data == null) { response.StatusCode = StatusCode.Warning; return(response); } var validation = ModelHelperValidator.ValidateComponentModel(User); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } User.UserName = User.UserName.Trim(); User.FirstName = User.FirstName.Trim(); User.LastName = User.LastName.Trim(); User.EmailAddress = User.EmailAddress.Trim(); if (users.Any(x => x.UserName == User.UserName) && User.UserName != response.Data.UserName) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The UserName already exists in the system."; return(response); } if (User.TeamId != null && !repositoryTeam.GetAll().Any(x => x.TeamId == User.TeamId)) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The Team doesn't exist in the system."; return(response); } response.Data.UserId = User.UserId; response.Data.UserName = User.UserName; response.Data.FirstName = User.FirstName; response.Data.LastName = User.LastName; response.Data.EmailAddress = User.EmailAddress; response.Data.TeamId = User.TeamId; repo.UpdateAndSave(response.Data); return(response); } }
public ResponseDto <Team> UpdateTeam(Team Team) { var response = new ResponseDto <Team>(StatusCode.Successful); using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repo = unitOfWork.GetGenericRepository <Team>(); var repositoryProject = unitOfWork.GetGenericRepository <Project>(); IQueryable <Team> teams = repo.GetAll(); response.Data = teams.FirstOrDefault(x => x.TeamId == Team.TeamId); if (response.Data == null) { response.StatusCode = StatusCode.Warning; return(response); } var validation = ModelHelperValidator.ValidateComponentModel(Team); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } if (teams.Any(x => x.TeamName == Team.TeamName) && Team.TeamName != response.Data.TeamName) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The team name already exists in the system."; return(response); } if (!repositoryProject.GetAll().Any(x => x.ProjectId == Team.ProjectId)) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The project doesn't exist in the system."; return(response); } response.Data.TeamId = Team.TeamId; response.Data.TeamName = Team.TeamName; response.Data.ProjectId = Team.ProjectId; repo.UpdateAndSave(response.Data); return(response); } }
public ResponseDto <Team> AddTeam(Team Team) { var response = new ResponseDto <Team> { StatusCode = StatusCode.Error }; var validation = ModelHelperValidator.ValidateComponentModel(Team); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repository = unitOfWork.GetGenericRepository <Team>(); var repositoryProject = unitOfWork.GetGenericRepository <Project>(); Team.TeamName = Team.TeamName.Trim(); if (repository.GetAll().Any(x => x.TeamName == Team.TeamName)) { response.StatusMessage = "The team name already exists in the system."; return(response); } if (!repositoryProject.GetAll().Any(x => x.ProjectId == Team.ProjectId)) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The project doesn't exist in the system."; return(response); } Team.CreatedDt = DateTime.Now; repository.InsertAndSave(Team); response.StatusCode = StatusCode.Successful; response.Data = Team; } return(response); }
public ResponseDto <Activity> UpdateActivity(Activity Activity) { var response = new ResponseDto <Activity>(StatusCode.Successful); using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repo = unitOfWork.GetGenericRepository <Activity>(); var repositoryTeam = unitOfWork.GetGenericRepository <Team>(); IQueryable <Activity> activities = repo.GetAll(); response.Data = activities.FirstOrDefault(x => x.ActivityId == Activity.ActivityId); if (response.Data == null) { response.StatusCode = StatusCode.Warning; return(response); } var validation = ModelHelperValidator.ValidateComponentModel(Activity); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } if (!repositoryTeam.GetAll().Any(x => x.TeamId == Activity.TeamId)) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The team doesn't exist in the system."; return(response); } response.Data.ActivityId = Activity.ActivityId; response.Data.Description = Activity.Description; response.Data.StartDate = Activity.StartDate; response.Data.DueDate = Activity.DueDate; repo.UpdateAndSave(response.Data); return(response); } }
public ResponseDto <User> AddUser(User User) { var response = new ResponseDto <User> { StatusCode = StatusCode.Error }; var validation = ModelHelperValidator.ValidateComponentModel(User); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repository = unitOfWork.GetGenericRepository <User>(); User.UserName = User.UserName.Trim(); User.FirstName = User.FirstName.Trim(); User.LastName = User.LastName.Trim(); User.EmailAddress = User.EmailAddress.Trim(); if (repository.GetAll().Any(x => x.UserName == User.UserName)) { response.StatusMessage = "The UserName already exists in the system."; return(response); } User.CreatedDt = DateTime.Now; repository.InsertAndSave(User); response.StatusCode = StatusCode.Successful; response.Data = User; } return(response); }
public ResponseDto <Project> UpdateProject(Project project) { var response = new ResponseDto <Project>(StatusCode.Successful); using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repo = unitOfWork.GetGenericRepository <Project>(); response.Data = repo.GetAll().FirstOrDefault(x => x.ProjectId == project.ProjectId); if (response.Data == null) { response.StatusCode = StatusCode.Warning; return(response); } var validation = ModelHelperValidator.ValidateComponentModel(project); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } if (repo.GetAll().Any(x => x.ProjectName == project.ProjectName) && project.ProjectName != response.Data.ProjectName) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The project name already exits in the system."; return(response); } response.Data.ProjectName = project.ProjectName; response.Data.Description = project.Description; response.Data.StartDate = project.StartDate; response.Data.EndDate = project.EndDate; repo.UpdateAndSave(response.Data); return(response); } }
public ResponseDto <Deliverable> UpdateDeliverable(Deliverable Deliverable) { var response = new ResponseDto <Deliverable>(StatusCode.Successful); using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repo = unitOfWork.GetGenericRepository <Deliverable>(); response.Data = repo.GetAll().FirstOrDefault(x => x.DeliverableId == Deliverable.DeliverableId); if (response.Data == null) { response.StatusCode = StatusCode.Warning; return(response); } var validation = ModelHelperValidator.ValidateComponentModel(Deliverable); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } if (repo.GetAll().Any(x => x.DeliverableId == Deliverable.DeliverableId) && Deliverable.DeliverableId != response.Data.DeliverableId) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The Deliverable name already exits in the system."; return(response); } response.Data.DeliverableId = Deliverable.DeliverableId; response.Data.Description = Deliverable.Description; response.Data.DueDate = Deliverable.DueDate; repo.UpdateAndSave(response.Data); return(response); } }
public ResponseDto <Project> AddProject(Project project) { var response = new ResponseDto <Project> { StatusCode = StatusCode.Error }; var validation = ModelHelperValidator.ValidateComponentModel(project); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repository = unitOfWork.GetGenericRepository <Project>(); project.ProjectName = project.ProjectName.Trim(); project.Description = project.Description.Trim(); if (repository.GetAll().Any(x => x.ProjectName == project.ProjectName)) { response.StatusMessage = "The project name already exits in the system."; return(response); } project.CreatedDt = DateTime.Now; repository.InsertAndSave(project); response.StatusCode = StatusCode.Successful; response.Data = project; } return(response); }
public ResponseDto <Deliverable> AddDeliverable(Deliverable Deliverable) { var response = new ResponseDto <Deliverable> { StatusCode = StatusCode.Error }; var validation = ModelHelperValidator.ValidateComponentModel(Deliverable); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repository = unitOfWork.GetGenericRepository <Deliverable>(); Deliverable.DeliverableId = Deliverable.DeliverableId; Deliverable.Description = Deliverable.Description.Trim(); if (repository.GetAll().Any(x => x.DeliverableId == Deliverable.DeliverableId)) { response.StatusMessage = "The Deliverable name already exits in the system."; return(response); } Deliverable.CreatedDt = DateTime.Now; repository.InsertAndSave(Deliverable); response.StatusCode = StatusCode.Successful; response.Data = Deliverable; } return(response); }
public ResponseDto <Activity> AddActivity(Activity Activity) { var response = new ResponseDto <Activity> { StatusCode = StatusCode.Error }; var validation = ModelHelperValidator.ValidateComponentModel(Activity); if (!validation.Data) { response.StatusCode = StatusCode.Error; response.StatusMessage = validation.StatusMessage.Trim(); return(response); } using (var unitOfWork = UnitOfWorkFactory.GetUnitOfWork()) { var repository = unitOfWork.GetGenericRepository <Activity>(); var repositoryTeam = unitOfWork.GetGenericRepository <Team>(); Activity.Description = Activity.Description.Trim(); Activity.CreatedDt = DateTime.Now; if (!repositoryTeam.GetAll().Any(x => x.TeamId == Activity.TeamId)) { response.StatusCode = StatusCode.Error; response.StatusMessage = "The Team doesn't exist in the system."; return(response); } repository.InsertAndSave(Activity); response.StatusCode = StatusCode.Successful; response.Data = Activity; } return(response); }