Ejemplo n.º 1
0
        public static string Edit(RankDTO Rank)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error = null;

                var toModify = db.Ranks.Where(x => x.Id == Rank.Id).FirstOrDefault();

                toModify.Name          = Rank.Name;
                toModify.Description   = Rank.Description;
                toModify.MinExperience = Rank.MinExperience;
                toModify.CanLead       = Rank.CanLead;
                toModify.Bonus         = Rank.Bonus;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 2
0
        public static string Add(string name, string description, int?bonus, bool canLead, int minExperience)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error   = null;
                Rank   newRank = new Rank();
                newRank.Name          = name;
                newRank.Description   = description;
                newRank.MinExperience = minExperience;
                newRank.CanLead       = canLead;
                newRank.Bonus         = bonus;

                var context = new ValidationContext(newRank, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newRank, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Ranks.Add(newRank);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 3
0
        public static string Edit(MissionDTO Mission)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error = null;

                var toModify = db.Missions.Where(x => x.Id == Mission.Id).FirstOrDefault();

                toModify.Name          = Mission.Name;
                toModify.Description   = Mission.Description;
                toModify.MissionTypeId = Mission.MissionTypeId;
                toModify.StartTime     = Mission.StartTime;
                toModify.EndTime       = Mission.EndTime;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 4
0
        public static string Edit(BarrackDTO Barrack)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error = null;

                var toModify = db.Barracks.Where(x => x.Id == Barrack.Id).FirstOrDefault();

                toModify.Name     = Barrack.Name;
                toModify.Capacity = Barrack.Capacity;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 5
0
        public static string Add(string name, string description, int?minRankId)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string     error         = null;
                Permission newPermission = new Permission();
                newPermission.Name        = name;
                newPermission.Description = description;
                newPermission.MinRankId   = minRankId;

                var context = new ValidationContext(newPermission, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newPermission, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Permissions.Add(newPermission);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 6
0
        public static string Add(int nationalId, string firstName, string lastName, double salary, int?specializationId, DateTime dateOfEmployment, int?rankId, int?teamId = null, int?barrackId = null)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string   error       = null;
                Employee newEmployee = new Employee();
                newEmployee.NationalId       = nationalId;
                newEmployee.FirstName        = firstName;
                newEmployee.LastName         = lastName;
                newEmployee.Salary           = salary;
                newEmployee.SpecializationId = specializationId;
                newEmployee.DateOfEmployment = dateOfEmployment;
                newEmployee.RankId           = rankId;
                newEmployee.TeamId           = teamId;
                newEmployee.BarrackId        = barrackId;

                var context = new ValidationContext(newEmployee, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newEmployee, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Employees.Add(newEmployee);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 7
0
        public static string Add(MissionDTO newMissionDTO)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string  error      = null;
                Mission newMission = new Mission();
                newMission.Name          = newMissionDTO.Name;
                newMission.Description   = newMissionDTO.Description;
                newMission.MissionTypeId = newMissionDTO.MissionTypeId;
                newMission.StartTime     = newMissionDTO.StartTime;
                newMission.EndTime       = newMissionDTO.EndTime;

                var context = new ValidationContext(newMission, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newMission, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Missions.Add(newMission);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 8
0
        public static string Edit(EquipmentDTO Equipment)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error = null;

                var toModify = db.Equipments.Where(x => x.Id == Equipment.Id).FirstOrDefault();

                toModify.Name            = Equipment.Name;
                toModify.EquipmentTypeId = Equipment.EquipmentTypeId;
                toModify.Quantity        = Equipment.Quantity;
                toModify.Description     = Equipment.Description;
                toModify.IsAvailable     = Equipment.IsAvailable;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 9
0
 public static List <EmployeeDTO> GetAll()
 {
     using (ArmyBaseContext db = new ArmyBaseContext())
     {
         var result = db.Employees.Where(x => x.IsDisabled == false).Select(
             x => new EmployeeDTO
         {
             Id                 = x.Id,
             NationalId         = x.NationalId,
             FirstName          = x.FirstName,
             LastName           = x.LastName,
             IsBarrackManager   = x.IsBarrackManager,
             IsTeamLeader       = x.IsTeamLeader,
             Salary             = x.Salary,
             SpecializationId   = x.SpecializationId,
             DateOfEmployment   = x.DateOfEmployment,
             RankId             = x.RankId,
             TeamId             = x.TeamId,
             BarrackId          = x.BarrackId,
             SpecializationName = x.Specialization != null ? x.Specialization.Name : "",
             RankName           = x.Rank != null ? x.Rank.Name : "",
             TeamName           = x.Team != null ? x.Team.Name : "",
             BarrackName        = x.Barrack != null ? x.Barrack.Name : "",
         }).ToList();
         return(result);
     }
 }
Ejemplo n.º 10
0
        public static string Edit(TeamDTO Team)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error = null;

                var toModify = db.Teams.Where(x => x.Id == Team.Id).FirstOrDefault();

                toModify.Name             = Team.Name;
                toModify.TeamTypeId       = Team.TeamTypeId;
                toModify.Responsibilities = Team.Responsibilities;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 11
0
        public static string Add(string name, int?equipmentTypeId, int quantity, string description, bool isAvailable)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string    error        = null;
                Equipment newEquipment = new Equipment();
                newEquipment.Name            = name;
                newEquipment.EquipmentTypeId = equipmentTypeId;
                newEquipment.Quantity        = quantity;
                newEquipment.Description     = description;
                newEquipment.IsAvailable     = isAvailable;

                var context = new ValidationContext(newEquipment, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newEquipment, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Equipments.Add(newEquipment);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 12
0
        public static string Add(string name, int capacity)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string  error      = null;
                Barrack newBarrack = new Barrack();
                newBarrack.Name     = name;
                newBarrack.Capacity = capacity;



                var context = new ValidationContext(newBarrack, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newBarrack, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }



                if (error == null)
                {
                    db.Barracks.Add(newBarrack);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 13
0
        public static string Add(string name)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string   error       = null;
                TeamType newTeamType = new TeamType();
                newTeamType.Name = name;

                var context = new ValidationContext(newTeamType, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newTeamType, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.TeamTypes.Add(newTeamType);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 14
0
        public static string Add(string name, int?teamTypeId, string responsibilities)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error   = null;
                Team   newTeam = new Team();
                newTeam.Name             = name;
                newTeam.TeamTypeId       = teamTypeId;
                newTeam.Responsibilities = responsibilities;

                var context = new ValidationContext(newTeam, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newTeam, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.Teams.Add(newTeam);
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 15
0
        public static string Edit(EmployeeDTO employee)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                string error = null;

                var toModify = db.Employees.Where(x => x.Id == employee.Id).FirstOrDefault();

                toModify.NationalId       = employee.NationalId;
                toModify.FirstName        = employee.FirstName;
                toModify.LastName         = employee.LastName;
                toModify.Salary           = employee.Salary;
                toModify.SpecializationId = employee.SpecializationId;
                toModify.DateOfEmployment = employee.DateOfEmployment;
                toModify.RankId           = employee.RankId;
                toModify.TeamId           = employee.TeamId;
                toModify.BarrackId        = employee.BarrackId;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
Ejemplo n.º 16
0
 public static BindableCollection <BarrackDTO> GetAllBindableCollection()
 {
     using (ArmyBaseContext db = new ArmyBaseContext())
     {
         var result = new BindableCollection <BarrackDTO>(GetAll());
         return(result);
     }
 }
Ejemplo n.º 17
0
        public static List <IMyObserver> GetAllObservers(int missionId)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var observers = TeamService.GetAll().Where(x => x.MissionId == missionId).ToList <IMyObserver>();

                return(observers);
            }
        }
Ejemplo n.º 18
0
        public static void Delete(MissionDTO Mission)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var toDelete = db.Missions.Where(x => x.Id == Mission.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }
Ejemplo n.º 19
0
        public static void Delete(TeamDTO Team)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var toDelete = db.Teams.Where(x => x.Id == Team.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }
Ejemplo n.º 20
0
        public static void Delete(EquipmentDTO Equipment)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var toDelete = db.Equipments.Where(x => x.Id == Equipment.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }
Ejemplo n.º 21
0
        public static void Delete(BarrackDTO Barrack)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var toDelete = db.Barracks.Where(x => x.Id == Barrack.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }
Ejemplo n.º 22
0
        public static void Delete(EmployeeDTO Employee)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var toDelete = db.Employees.Where(x => x.Id == Employee.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }
Ejemplo n.º 23
0
        public static void RemoveFromMission(TeamDTO Team)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var toDelete = db.Teams.Where(x => x.Id == Team.Id).FirstOrDefault();
                toDelete.MissionId = null;

                db.SaveChanges();
            }
        }
Ejemplo n.º 24
0
 public static List <TeamTypeDTO> GetAll()
 {
     using (ArmyBaseContext db = new ArmyBaseContext())
     {
         var result = db.TeamTypes.Where(x => x.IsDisabled == false).Select(
             x => new TeamTypeDTO
         {
             Id   = x.Id,
             Name = x.Name,
         }).ToList();
         return(result);
     }
 }
Ejemplo n.º 25
0
 public static List <SpecializationDTO> GetAll()
 {
     using (ArmyBaseContext db = new ArmyBaseContext())
     {
         var result = db.Specializations.Where(x => x.IsDisabled == false).Select(
             x => new SpecializationDTO
         {
             Id          = x.Id,
             Name        = x.Name,
             Description = x.Description,
         }).ToList();
         return(result);
     }
 }
Ejemplo n.º 26
0
 public static List <BarrackDTO> GetAll()
 {
     using (ArmyBaseContext db = new ArmyBaseContext())
     {
         var result = db.Barracks.Where(x => x.IsDisabled == false).Select(
             x => new BarrackDTO
         {
             Id       = x.Id,
             Capacity = x.Capacity,
             Name     = x.Name
         }).ToList();
         return(result);
     }
 }
Ejemplo n.º 27
0
        public static TeamTypeDTO GetById(int id)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var result = db.TeamTypes.Where(x => x.Id == id).Select(
                    x => new TeamTypeDTO
                {
                    Id   = x.Id,
                    Name = x.Name,
                }).FirstOrDefault();

                return(result);
            }
        }
Ejemplo n.º 28
0
        public static BarrackDTO GetById(int id)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var result = db.Barracks.Where(x => x.Id == id).Select(
                    x => new BarrackDTO
                {
                    Id       = x.Id,
                    Capacity = x.Capacity,
                    Name     = x.Name
                }).FirstOrDefault();

                return(result);
            }
        }
Ejemplo n.º 29
0
        public static SpecializationDTO GetById(int id)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var result = db.Specializations.Where(x => x.Id == id).Select(
                    x => new SpecializationDTO
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                }).FirstOrDefault();

                return(result);
            }
        }
Ejemplo n.º 30
0
        public static PermissionDTO GetById(int id)
        {
            using (ArmyBaseContext db = new ArmyBaseContext())
            {
                var result = db.Permissions.Where(x => x.Id == id).Select(
                    x => new PermissionDTO
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    MinRankId   = x.MinRankId
                }).FirstOrDefault();

                return(result);
            }
        }