public ChangeResult AddUserDetail(List <IUserDetail> userDetails)
        {
            var result = Validate(userDetails, isAddNew: true);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in userDetails)
                    {
                        context.UserDetails.Add(new Domain.UserDetail()
                        {
                            UserDetailId     = item.UserDetailId == Guid.Empty ? Guid.NewGuid().ToString() : item.UserDetailId.ToString(),
                            UserId           = item.UserId.ToString(),
                            Characteristic   = Helper.CleanString(item.Characteristic),
                            Description      = Helper.CleanString(item.Description),
                            CreateUserId     = item.CreateUserId.ToString(),
                            LastUpdateDate   = DateTime.UtcNow,
                            ProficiencyLevel = (int)item.ProficiencyLevel,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = item.DeleteDate
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #2
0
        public WarrantyNoteServiceTesting()
        {
            Data.ScheduleContext scheduleContext = new Data.ScheduleContext();
            scheduleContext.Migrate();

            Service = new WarrantyNoteService();
        }
        public ChangeResult UpdateScheduleNote(List <IScheduleNote> scheduleNotes)
        {
            var result = Validate(scheduleNotes);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in scheduleNotes)
                    {
                        context.ScheduleNotes.Update(new Domain.ScheduleNote()
                        {
                            ScheduleNoteId   = item.ScheduleNoteId.ToString(),
                            ScheduleId       = item.ScheduleId.ToString(),
                            Note             = Helper.CleanString(item.Note),
                            StartDate        = item.StartDate,
                            EndDate          = item.EndDate,
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = item.DeleteDate
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #4
0
        public ChangeResult UpdateTeamCategory(List <ITeamCategory> teamCategories)
        {
            var result = Validate(teamCategories);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in teamCategories)
                    {
                        context.TeamCategories.Update(new Domain.TeamCategory()
                        {
                            TeamCategoryId   = item.TeamCategoryId.ToString(),
                            TeamId           = item.TeamId.ToString(),
                            CategoryId       = item.CategoryId.ToString(),
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = item.DeleteDate
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #5
0
        public ChangeResult MarkScheduleDeleted(Guid scheduleId)
        {
            ChangeResult result = new ChangeResult();

            var update = GetSchedule(scheduleId);

            using (var context = new Data.ScheduleContext())
            {
                if (update != null && !update.DeleteDate.HasValue)
                {
                    context.Schedules.Update(new Domain.Schedule
                    {
                        ScheduleId       = update.ScheduleId.ToString(),
                        TeamId           = update.TeamId.ToString(),
                        UserId           = update.UserId.ToString(),
                        StartDate        = update.StartDate,
                        EndDate          = update.EndDate,
                        SupportLevel     = (int)update.SupportLevel,
                        LastUpdateDate   = DateTime.UtcNow,
                        LastUpdateUserId = update.LastUpdateUserId.ToString(),
                        DeleteDate       = DateTime.UtcNow
                    });

                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #6
0
        public TeamUserServiceTesting()
        {
            Data.ScheduleContext context = new Data.ScheduleContext();
            context.Migrate();

            Service = new TeamUserService();
        }
Example #7
0
        /// <summary>
        /// Fixs the potential duplications.
        /// In an attempt to always make what the user enters part of the new schedule, there is the potential for duplications to sneak in.
        /// This fixes them.
        /// </summary>
        /// <param name="teamId">Team identifier.</param>
        /// <param name="startDate">Start date.</param>
        /// <param name="endDate">End date.</param>
        private void FixPotentialDuplications(Guid teamId, DateTime startDate, DateTime endDate)
        {
            using (var context = new Data.ScheduleContext())
            {
                var items = context.Schedules.Where(x => x.TeamId == teamId.ToString() &&
                                                    ((x.StartDate >= startDate && x.StartDate <= endDate) ||
                                                     (x.EndDate >= startDate && x.EndDate <= endDate) ||
                                                     (x.StartDate <= startDate && x.EndDate >= endDate)) &&
                                                    !x.DeleteDate.HasValue).ToList();

                bool     hasItemsToRemove = false;
                DateTime?priorStart       = null;
                DateTime?priorEnd         = null;
                int?     priorLevel       = null;

                foreach (var item in items.OrderBy(x => x.SupportLevel).ThenBy(x => x.StartDate).ThenByDescending(x => x.CreateDate))
                {
                    if (item.StartDate == priorStart && item.EndDate == priorEnd && item.SupportLevel == priorLevel)
                    {
                        context.Schedules.Remove(item);
                        hasItemsToRemove = true;
                    }

                    priorLevel = item.SupportLevel;
                    priorStart = item.StartDate;
                    priorEnd   = item.EndDate;
                }

                if (hasItemsToRemove)
                {
                    context.SaveChanges();
                }
            }
        }
Example #8
0
        public ChangeResult AddLocation(List <ILocation> locations)
        {
            var result = Validate(locations, isAddNew: true);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in locations)
                    {
                        context.Locations.Add(new Domain.Location()
                        {
                            LocationId       = item.LocationId == Guid.Empty ? Guid.NewGuid().ToString() : item.LocationId.ToString(),
                            LocationName     = Helper.CleanString(item.LocationName),
                            Description      = Helper.CleanString(item.Description),
                            Address          = Helper.CleanString(item.Address),
                            City             = Helper.CleanString(item.City),
                            StateRegion      = Helper.CleanString(item.StateRegion),
                            Country          = Helper.CleanString(item.Country),
                            ZipCode          = Helper.CleanString(item.ZipCode),
                            CreateDate       = DateTime.UtcNow,
                            CreateUserId     = item.CreateUserId.ToString(),
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = item.DeleteDate
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
        public ChangeResult AddWarrantyNote(List <IWarrantyNote> notes)
        {
            var result = Validate(notes, isAddNew: true);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in notes)
                    {
                        context.WarrantyNotes.Add(new Domain.WarrantyNote()
                        {
                            WarrantyNoteId   = item.WarrantyNoteId == Guid.Empty ? Guid.NewGuid().ToString() : item.WarrantyNoteId.ToString(),
                            WarrantyId       = item.WarrantyId.ToString(),
                            Note             = Helper.CleanString(item.Note),
                            StartDate        = item.StartDate,
                            EndDate          = item.EndDate,
                            CreateDate       = DateTime.UtcNow,
                            CreateUserId     = item.CreateUserId.ToString(),
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = null
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #10
0
        public ChangeResult AddTeamUser(List <ITeamUser> teamUsers)
        {
            var result = Validate(teamUsers, isAddNew: true);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in teamUsers)
                    {
                        context.TeamUsers.Add(new Domain.TeamUser()
                        {
                            TeamUserId       = item.TeamUserId == Guid.Empty ? Guid.NewGuid().ToString() : item.TeamUserId.ToString(),
                            TeamId           = item.TeamId.ToString(),
                            UserId           = item.UserId.ToString(),
                            CreateDate       = DateTime.UtcNow,
                            CreateUserId     = item.CreateUserId.ToString(),
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = item.DeleteDate
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
        public List <IScheduleNote> GetScheduleNotes(Guid scheduleId, DateTime?startDate = null, DateTime?endDate = null)
        {
            List <IScheduleNote> scheduleNotes = new List <IScheduleNote>();

            using (var context = new Data.ScheduleContext())
            {
                var items = context.ScheduleNotes.Where(x => x.ScheduleId == scheduleId.ToString() && !x.DeleteDate.HasValue);
                foreach (var item in items)
                {
                    scheduleNotes.Add(Mapper.Map <ScheduleNoteDto>(item));
                }
            }

            if (startDate.HasValue)
            {
                scheduleNotes = scheduleNotes.Where(x => x.StartDate >= startDate.Value || x.EndDate >= startDate.Value).ToList();
            }

            if (endDate.HasValue)
            {
                scheduleNotes = scheduleNotes.Where(x => x.StartDate <= endDate.Value || x.EndDate <= endDate.Value).ToList();
            }

            return(scheduleNotes);
        }
Example #12
0
        public ChangeResult UpdateCategory(List <ICategory> categories)
        {
            var result = Validate(categories);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in categories)
                    {
                        context.Categories.Update(new Domain.Category()
                        {
                            CategoryId          = item.CategoryId.ToString(),
                            CategoryName        = Helper.CleanString(item.CategoryName),
                            CategoryDescription = Helper.CleanString(item.CategoryDescription),
                            CategoryEmail       = Helper.CleanString(item.CategoryEmail),
                            LastUpdateDate      = DateTime.UtcNow,
                            LastUpdateUserId    = item.LastUpdateUserId.ToString(),
                            DeleteDate          = item.DeleteDate
                        });
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #13
0
        public ChangeResult UpdateTeam(List <ITeam> teams)
        {
            var result = Validate(teams);

            if (result.IsSuccess)
            {
                using (var context = new Data.ScheduleContext())
                {
                    foreach (var item in teams)
                    {
                        context.Teams.Update(new Domain.Team()
                        {
                            TeamId           = item.TeamId.ToString(),
                            TeamName         = Helper.CleanString(item.TeamName),
                            TeamDescription  = Helper.CleanString(item.TeamDescription),
                            TeamLeaderId     = item.TeamLeaderId.HasValue ? item.TeamLeaderId.Value.ToString() : null,
                            LocationId       = item.LocationId.ToString(),
                            TeamEmail        = Helper.CleanString(item.TeamEmail),
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = item.LastUpdateUserId.ToString(),
                            DeleteDate       = item.DeleteDate
                        });
                        result.Ids.Add(item.TeamId);
                    }
                    context.SaveChanges();
                }
            }
            return(result);
        }
Example #14
0
        public UserServiceTesting()
        {
            Data.ScheduleContext context = new Data.ScheduleContext();
            context.Migrate();

            TestUserId = Guid.NewGuid();
            Service    = new UserService();
        }
        public CategoryServiceTesting()
        {
            Data.ScheduleContext context = new Data.ScheduleContext();
            context.Migrate();

            Service        = new CategoryService();
            TestCategoryId = Guid.NewGuid();
        }
        public TeamServiceTesting()
        {
            Data.ScheduleContext context = new Data.ScheduleContext();
            context.Migrate();

            TeamService = new TeamService();

            TestTeamId = Guid.NewGuid();
        }
Example #17
0
        public ChangeResult SaveTeamCategories(Guid teamId, List <Guid> categoryIds, Guid?changeUserId = null)
        {
            ChangeResult result = new ChangeResult();

            using (var context = new Data.ScheduleContext())
            {
                var         existingTeamCats = context.TeamCategories.Where(x => x.TeamId == teamId.ToString());
                List <Guid> existingCatIds   = new List <Guid>();

                foreach (var item in existingTeamCats)
                {
                    if (!categoryIds.Contains(Guid.Parse(item.CategoryId)) && !item.DeleteDate.HasValue)
                    {
                        item.DeleteDate     = DateTime.UtcNow;
                        item.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            item.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    else if (item.DeleteDate.HasValue)
                    {
                        item.DeleteDate     = null;
                        item.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            item.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    existingCatIds.Add(Guid.Parse(item.CategoryId));
                }

                foreach (Guid categoryId in categoryIds)
                {
                    if (!existingCatIds.Contains(categoryId))
                    {
                        context.TeamCategories.Add(new Domain.TeamCategory()
                        {
                            TeamCategoryId   = Guid.NewGuid().ToString(),
                            CategoryId       = categoryId.ToString(),
                            TeamId           = teamId.ToString(),
                            CreateDate       = DateTime.UtcNow,
                            LastUpdateDate   = DateTime.UtcNow,
                            CreateUserId     = changeUserId.HasValue ? changeUserId.Value.ToString() : null,
                            LastUpdateUserId = changeUserId.HasValue ? changeUserId.Value.ToString() : null
                        });
                    }
                }

                context.SaveChanges();
            }

            return(result);
        }
Example #18
0
        public ChangeResult SaveTeamUsers(Guid teamId, List <Guid> userIds, Guid?changeUserId = null)
        {
            ChangeResult result = new ChangeResult();

            using (var context = new Data.ScheduleContext())
            {
                var         existingUsers   = context.TeamUsers.Where(x => x.TeamId == teamId.ToString()).ToList();
                List <Guid> existingUserIds = new List <Guid>();
                foreach (var user in existingUsers)
                {
                    if (!userIds.Contains(Guid.Parse(user.UserId)))
                    {
                        user.DeleteDate     = DateTime.UtcNow;
                        user.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            user.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    else if (user.DeleteDate.HasValue)
                    {
                        user.DeleteDate     = null;
                        user.LastUpdateDate = DateTime.UtcNow;
                        if (changeUserId.HasValue)
                        {
                            user.LastUpdateUserId = changeUserId.Value.ToString();
                        }
                    }
                    existingUserIds.Add(Guid.Parse(user.UserId));
                }

                foreach (Guid userId in userIds)
                {
                    if (!existingUserIds.Contains(userId))
                    {
                        context.TeamUsers.Add(new Domain.TeamUser()
                        {
                            TeamUserId       = Guid.NewGuid().ToString(),
                            TeamId           = teamId.ToString(),
                            UserId           = userId.ToString(),
                            CreateDate       = DateTime.UtcNow,
                            CreateUserId     = changeUserId.HasValue ? changeUserId.Value.ToString() : null,
                            LastUpdateDate   = DateTime.UtcNow,
                            LastUpdateUserId = changeUserId.HasValue ? changeUserId.Value.ToString() : null,
                            DeleteDate       = null
                        });
                    }
                }

                context.SaveChanges();
            }

            return(result);
        }
Example #19
0
        public UserDetailServiceTesting()
        {
            Data.ScheduleContext context = new Data.ScheduleContext();
            context.Migrate();

            UserDetailService = new UserDetailService();
            UserService       = new UserService();

            TestUserDetailId     = Guid.NewGuid();
            TestProficiencyLevel = ProficiencyLevelType.Medium;
        }
Example #20
0
        private void PurgeOldDeletedRecords(int daysOld = 90)
        {
            using (var context = new Data.ScheduleContext())
            {
                var items = context.Schedules.Where(x => x.DeleteDate.HasValue && x.DeleteDate <= DateTime.UtcNow.AddDays(-daysOld));
                foreach (var item in items)
                {
                    context.Schedules.Remove(item);
                }

                context.SaveChanges();
            }
        }
Example #21
0
        public IWarranty GetWarranty(Guid warrantyId)
        {
            IWarranty warranty = null;

            using (var context = new Data.ScheduleContext())
            {
                var item = context.Warranties.FirstOrDefault(x => x.WarrantyId == warrantyId.ToString());
                if (item != null)
                {
                    warranty = Mapper.Map <WarrantyDto>(item);
                }
            }
            return(warranty);
        }
Example #22
0
        public List <ITeamUser> GetTeamUsers()
        {
            List <ITeamUser> teamUsers = new List <ITeamUser>();

            using (var context = new Data.ScheduleContext())
            {
                var items = context.TeamUsers.Where(x => !x.DeleteDate.HasValue);
                foreach (var item in items)
                {
                    teamUsers.Add(Mapper.Map <TeamUserDto>(item));
                }
            }
            return(teamUsers);
        }
Example #23
0
        public ITeam GetTeam(Guid teamId)
        {
            ITeam team = null;

            using (var context = new Data.ScheduleContext())
            {
                var item = context.Teams.FirstOrDefault(x => x.TeamId == teamId.ToString());
                if (item != null)
                {
                    team = Mapper.Map <TeamDto>(item);
                }
            }
            return(team);
        }
Example #24
0
        public List <ITeam> GetLocationTeams(Guid locationId)
        {
            List <ITeam> teams = new List <ITeam>();

            using (var context = new Data.ScheduleContext())
            {
                var items = context.Teams.Where(x => x.LocationId == locationId.ToString() && !x.DeleteDate.HasValue);
                foreach (var item in items)
                {
                    teams.Add(Mapper.Map <TeamDto>(item));
                }
            }
            return(teams);
        }
Example #25
0
        public ITeamUser GetTeamUser(Guid teamId, Guid userId)
        {
            ITeamUser teamUser = null;

            using (var context = new Data.ScheduleContext())
            {
                var item = context.TeamUsers.FirstOrDefault(x => x.TeamId == teamId.ToString() && x.UserId == userId.ToString());
                if (item != null)
                {
                    teamUser = Mapper.Map <TeamUserDto>(item);
                }
            }
            return(teamUser);
        }
        public IScheduleNote GetScheduleNote(Guid scheduleNoteId)
        {
            IScheduleNote scheduleNote = null;

            using (var context = new Data.ScheduleContext())
            {
                var item = context.ScheduleNotes.FirstOrDefault(x => x.ScheduleNoteId == scheduleNoteId.ToString());
                if (item != null)
                {
                    scheduleNote = Mapper.Map <ScheduleNoteDto>(item);
                }
            }
            return(scheduleNote);
        }
Example #27
0
        public ICategory GetCategory(Guid categoryId)
        {
            ICategory category = null;

            using (var context = new Data.ScheduleContext())
            {
                var item = context.Categories.FirstOrDefault(x => x.CategoryId == categoryId.ToString());
                if (item != null)
                {
                    category = Mapper.Map <CategoryDto>(item);
                }
            }
            return(category);
        }
Example #28
0
        public List <ITeamCategory> GetTeamCategoriesByTeamId(Guid teamId)
        {
            List <ITeamCategory> teamCategories = new List <ITeamCategory>();

            using (var context = new Data.ScheduleContext())
            {
                var items = context.TeamCategories.Where(x => x.TeamId == teamId.ToString() && !x.DeleteDate.HasValue);
                foreach (var item in items)
                {
                    teamCategories.Add(Mapper.Map <TeamCategoryDto>(item));
                }
            }
            return(teamCategories);
        }
Example #29
0
        public ITeamCategory GetTeamCategory(Guid teamId, Guid categoryId)
        {
            ITeamCategory teamCategory = null;

            using (var context = new Data.ScheduleContext())
            {
                var item = context.TeamCategories.FirstOrDefault(x => x.TeamId == teamId.ToString() && x.CategoryId == categoryId.ToString());
                if (item != null)
                {
                    teamCategory = Mapper.Map <TeamCategoryDto>(item);
                }
            }
            return(teamCategory);
        }
Example #30
0
        public List <ICategory> GetCategories()
        {
            List <ICategory> categories = new List <ICategory>();

            using (var context = new Data.ScheduleContext())
            {
                var items = context.Categories.Where(x => !x.DeleteDate.HasValue);
                foreach (var item in items)
                {
                    categories.Add(Mapper.Map <CategoryDto>(item));
                }
            }
            return(categories);
        }