Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public AddMissionViewModel(MissionDTO mission)
        {
            IsEdit         = true;
            ButtonLabel    = "Edit";
            MissionTypes   = MissionTypeService.GetAllBindableCollection();
            AvailableTeams = new BindableCollection <TeamDTO>(TeamService.GetAll().Where(x => x.MissionId == null).ToList());
            ActualTeams    = new BindableCollection <TeamDTO>(TeamService.GetAll().Where(x => x.MissionId == mission.Id).ToList());

            int i = 0;

            while (ActualType == null)
            {
                if (MissionTypes[i].Id == mission.MissionTypeId)
                {
                    ActualType = i;
                    break;
                }
                else
                {
                    i++;
                }
            }

            this.toEdit = mission;
            Name        = mission.Name;
            Description = mission.Description;
            StartTime   = mission.StartTime;
            EndTime     = mission.EndTime;
            NotifyOfPropertyChange(() => Name);
            NotifyOfPropertyChange(() => Description);
            NotifyOfPropertyChange(() => StartTime);
            NotifyOfPropertyChange(() => EndTime);
        }
Exemplo n.º 3
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);
            }
        }
        public MissionDetailsPageViewModel(INavigationService navigationService, IModalNavigationService modalNavigationService, IPageDialogService dialogService, IAppService appService)
            : base(navigationService, modalNavigationService, dialogService, appService)
        {
            Mission = new MissionDTO();
            Title   = "Mission";

            // Reload the page if the mission was edited
            MessagingCenter.Subscribe <NewMissionPageViewModel, MissionDTO>(this, MessagingCenterMessages.NewMission, async(sender, mission) =>
            {
                try
                {
                    IsBusy = true;
                    if (Mission?.Id == mission.Id)
                    {
                        await ReloadPage(mission.Id);
                    }
                }
                catch (Exception ex)
                {
                    base.DisplayExceptionMessage(ex);
                }
                finally
                {
                    IsBusy = false;
                }
            });
        }
Exemplo n.º 5
0
        public IHttpActionResult Create([FromBody] MissionDTO missionDTO)
        {
            try
            {
                var identity = RequestContext.Principal.Identity;
                var userId   = identity.GetUserId();

                // invalid user
                if (userId.IsEmpty())
                {
                    return(Unauthorized());
                }

                if (!ModelState.IsValid)
                {
                    var errors = string.Join($"{Environment.NewLine} - ", ModelState.GetErrors().ToArray());
                    AppLogger.Logger.Debug($"Create: Validation Error on new Mission by User {userId}{Environment.NewLine}{errors}");

                    return(BadRequest(errors));
                }

                missionDTO.CreatedByUserId = userId;
                missionDTO.CreatedDate     = DateTime.Now;

                missionDTO = AppService.Missions.Create(missionDTO, userId);

                return(Created(new Uri($"{Request.RequestUri}/{missionDTO.Id}"), missionDTO));
            }
            catch (Exception ex)
            {
                AppLogger.Logger.Error(ex);
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Inserts a new mission into the database
        /// </summary>
        /// <param name="missionDTO"></param>
        /// <param name="currentUserId"></param>
        /// <returns></returns>
        public MissionDTO Create(MissionDTO missionDTO, string currentUserId)
        {
            var mission = AutoMapper.Mapper.Map <Mission>(missionDTO);

            // Mission
            mission.CreatedByUserId = currentUserId;
            mission.CreatedDate     = DateTime.Now;

            // STEP 1: validate the minimum requirements
            ValidateMissionInput(mission);

            // if we get here it means that the mission is valid now let's calculate the route
            var pinPointsRoute = CreateRoute(ref mission); // this will also validate the pin-points

            mission.PinPoints = pinPointsRoute;

            ValidateMissionOutput(mission);

            // if we get here it means that all the pin-points in the route are valid we can persist
            using (var unitOfWork = new UnitOfWork())
            {
                var roversOnTheSameSpot = unitOfWork.Missions.Find(x => x.FinalX == mission.FinalX && x.FinalY == mission.FinalY);
                if (roversOnTheSameSpot != null && roversOnTheSameSpot.Count() > 0)
                {
                    throw new Exception($"Houston we have a problem!{Environment.NewLine}This rover would collide with another rover in the same final spot!{Environment.NewLine}Mission aborted!");
                }
                unitOfWork.Missions.Add(mission);
                unitOfWork.SaveChanges();
                mission    = unitOfWork.Missions.GetFull(mission.Id);
                missionDTO = AutoMapper.Mapper.Map <MissionDTO>(mission);
            }

            return(missionDTO);
        }
Exemplo n.º 7
0
        public void LoadModifyMissionPage(MissionDTO mission)
        {
            IWindowManager      manager = new WindowManager();
            AddMissionViewModel modify  = new AddMissionViewModel(mission);

            manager.ShowDialog(modify, null, null);
            Reload();
        }
Exemplo n.º 8
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();
            }
        }
Exemplo n.º 9
0
 public AddMissionViewModel()
 {
     IsEdit         = false;
     ButtonLabel    = "Add";
     MissionTypes   = MissionTypeService.GetAllBindableCollection();
     AvailableTeams = new BindableCollection <TeamDTO>(TeamService.GetAll().Where(x => x.MissionId == null).ToList());
     ActualTeams    = new BindableCollection <TeamDTO>();
     StartTime      = DateTime.Now;
     newMission     = new MissionDTO();
     NotifyOfPropertyChange(() => StartTime);
 }
Exemplo n.º 10
0
        public void Delete(MissionDTO mission)
        {
            IWindowManager manager             = new WindowManager();
            DeleteConfirmationViewModel modify = new DeleteConfirmationViewModel();
            bool?showDialogResult = manager.ShowDialog(modify, null, null);

            if (showDialogResult != null && showDialogResult == true)
            {
                mission.InformObservers();
                MissionService.Delete(mission);
            }
            Reload();
        }