Example #1
0
        public async Task Person_ResourcePerson_Create()
        {
            var testEntity   = new ResourcePerson();
            var resultEntity = new ResourcePerson();

            // Create should update original object, and pass back a fresh-from-db object
            testEntity.Fill(testEntities[Arithmetic.Random(1, testEntities.Count)]);
            using (var writer = new EntityWriter <ResourcePerson>(testEntity, new ResourcePersonSPConfig()))
            {
                resultEntity = await writer.SaveAsync();
            }
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(resultEntity.Id != Defaults.Integer);
            Assert.IsTrue(resultEntity.Key != Defaults.Guid);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Object in db should match in-memory objects
            var reader = new EntityReader <ResourcePerson>();

            testEntity = reader.GetByKey(resultEntity.Key);
            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(testEntity.Id == resultEntity.Id);
            Assert.IsTrue(testEntity.Key == resultEntity.Key);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            ResourcePersonTests.RecycleBin.Add(testEntity.Key);
        }
Example #2
0
        public static async Task Cleanup()
        {
            var reader   = new EntityReader <ResourcePerson>();
            var toDelete = new ResourcePerson();

            foreach (Guid item in RecycleBin)
            {
                toDelete = reader.GetAll().Where(x => x.Key == item).FirstOrDefaultSafe();
                using (var db = new EntityWriter <ResourcePerson>(toDelete, new ResourcePersonSPConfig()))
                {
                    await db.DeleteAsync();
                }
            }
        }
Example #3
0
        public ActionResult AssignPerson([Bind(Include = "ProjectId,UserId,")] AssignPersonViewModel model)
        {
            if (ModelState.IsValid)
            {
                var resource = new ResourcePerson();
                resource.ProjectId = Int32.Parse(model.ProjectId);
                resource.UserId    = model.UserId;

                db.ResourcePersons.Add(resource);
                db.SaveChanges();
                return(RedirectToAction("AssignPerson", "Project"));
            }
            ModelState.AddModelError("", "Unable to assign resource person");
            return(View(model));
        }
Example #4
0
        public async Task Person_ResourcePerson_Read()
        {
            var testEntity = new ResourcePerson();
            var lastKey    = Defaults.Guid;

            await Person_ResourcePerson_Create();

            lastKey = ResourcePersonTests.RecycleBin.LastOrDefault();

            testEntity = new EntityReader <ResourcePerson>().GetByKey(lastKey);
            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(testEntity.CreatedDate.Date == DateTime.UtcNow.Date);
            Assert.IsTrue(!testEntity.FailedRules.Any());
        }
Example #5
0
        public void Person_Person_Serialize()
        {
            var searchChar     = "i";
            var originalObject = new ResourcePerson()
            {
                FirstName = searchChar, LastName = searchChar
            };
            var resultObject = new ResourcePerson();
            var resultString = Defaults.String;
            var serializer   = new JsonSerializer <ResourcePerson>();

            resultString = serializer.Serialize(originalObject);
            Assert.IsTrue(resultString != Defaults.String);
            resultObject = serializer.Deserialize(resultString);
            Assert.IsTrue(resultObject.FirstName == searchChar);
            Assert.IsTrue(resultObject.LastName == searchChar);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Institute,Faculty,Department,Designation,Phone,Email,Specialization,SubSpecialization,Photo,ResearchAreas")] ResourcePerson resourcePerson, ICollection <string> ResearchAreas)
        {
            if (ModelState.IsValid)
            {
                var traceId  = Guid.NewGuid().ToString();
                var rootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\documents\\ResourcePerson", traceId);

                if (!Directory.Exists(rootPath))
                {
                    Directory.CreateDirectory(rootPath);
                }

                if (resourcePerson.Photo != null && resourcePerson.Photo.Length > 0)
                {
                    _fileService.UploadFile(resourcePerson.Photo, rootPath);
                    resourcePerson.PicFolderId   = traceId;
                    resourcePerson.PhotoFileName = resourcePerson.Photo.FileName;
                }

                foreach (string item in ResearchAreas)
                {
                    int value = 0;
                    if (int.TryParse(item, out value))
                    {
                        resourcePerson.ResearchAreas.Add(new ResearchArea {
                            ResearchInterestId = value
                        });
                    }
                    else
                    {
                        resourcePerson.ResearchAreas.Add(new ResearchArea {
                            ResearchInterest = new ResearchInterest {
                                AreaName = item
                            }
                        });
                    }
                }

                _context.Add(resourcePerson);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(resourcePerson));
        }
Example #7
0
        public async Task <ResourcePerson> GetResroucePerson(string no)
        {
            try
            {
                HttpClient client = ClientGateway.GetHttpClient;

                var response = await client.GetAsync(endPoint + no);

                var statsJson = response.Content.ReadAsStringAsync().Result;

                var rootObject = JsonConvert.DeserializeObject <ResourcePerson>(statsJson);

                return(rootObject);
            }
            catch
            {
                ResourcePerson ml = null;
                return(ml);
            }
        }
Example #8
0
        public async Task Person_ResourcePerson_Update()
        {
            var resultEntity = new ResourcePerson();
            var testEntity   = new ResourcePerson();
            var uniqueValue  = Guid.NewGuid().ToString().Replace("-", "");
            var lastKey      = Defaults.Guid;
            var originalId   = Defaults.Integer;
            var originalKey  = Defaults.Guid;

            await Person_ResourcePerson_Create();

            lastKey = ResourcePersonTests.RecycleBin.LastOrDefault();

            testEntity  = new EntityReader <ResourcePerson>().GetByKey(lastKey);
            originalId  = testEntity.Id;
            originalKey = testEntity.Key;
            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            testEntity.FirstName = uniqueValue;
            using (var writer = new EntityWriter <ResourcePerson>(testEntity, new ResourcePersonSPConfig()))
            {
                resultEntity = await writer.SaveAsync();
            }
            Assert.IsTrue(!resultEntity.IsNew);
            Assert.IsTrue(resultEntity.Id != Defaults.Integer);
            Assert.IsTrue(resultEntity.Key != Defaults.Guid);
            Assert.IsTrue(testEntity.Id == resultEntity.Id && resultEntity.Id == originalId);
            Assert.IsTrue(testEntity.Key == resultEntity.Key && resultEntity.Key == originalKey);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            testEntity = new EntityReader <ResourcePerson>().GetByKey(originalKey);
            Assert.IsTrue(!testEntity.IsNew);
            Assert.IsTrue(testEntity.Id == resultEntity.Id && resultEntity.Id == originalId);
            Assert.IsTrue(testEntity.Key == resultEntity.Key && resultEntity.Key == originalKey);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(!testEntity.FailedRules.Any());
        }
Example #9
0
        public async Task Person_ResourcePerson_Create_Key()
        {
            var testEntity   = new ResourcePerson();
            var resultEntity = new ResourcePerson();

            // Create and insert record
            testEntity.Fill(testEntities[Arithmetic.Random(1, testEntities.Count)]);
            testEntity.Id  = Defaults.Integer;
            testEntity.Key = Guid.NewGuid();
            var oldId  = testEntity.Id;
            var oldKey = testEntity.Key;

            Assert.IsTrue(testEntity.IsNew);
            Assert.IsTrue(testEntity.Id == Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Do Insert and check passed entity and returned entity
            using (var writer = new EntityWriter <ResourcePerson>(testEntity, new ResourcePersonSPConfig()))
            {
                resultEntity = await writer.SaveAsync();
            }
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(resultEntity.Id != Defaults.Integer);
            Assert.IsTrue(resultEntity.Key != Defaults.Guid);
            Assert.IsTrue(!resultEntity.FailedRules.Any());

            // Pull from DB and retest
            testEntity = new EntityReader <ResourcePerson>().GetById(resultEntity.Id);
            Assert.IsTrue(testEntity.IsNew == false);
            Assert.IsTrue(testEntity.Id != oldId);
            Assert.IsTrue(testEntity.Key == oldKey);
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Cleanup
            RecycleBin.Add(testEntity.Key);
        }
Example #10
0
        private async void Start_Clicked(object sender, EventArgs e)
        {
            HandleElements();
            if (workType == null)
            {
                await DisplayAlert("Fejl!", "Du skal en arbejdstype", "OK");
            }
            else
            {
                CheckForRunningRecLine();

                ResourcePerson        resourcePerson = null;
                List <ResourcePerson> rl             = await db.GetResourcePersonsAsync();

                resourcePerson = rl.Where(x => x.Name == gd.User.Name).FirstOrDefault();
                SetRecLineValues(resourcePerson.No);

                await db.SaveJobRecLineAsync(recLine);

                await Navigation.PopModalAsync();
            }
            HandleElements();
        }
Example #11
0
        public async Task Person_ResourcePerson_Delete()
        {
            var testEntity   = new ResourcePerson();
            var resultEntity = new ResourcePerson();
            var lastKey      = Defaults.Guid;
            var originalId   = Defaults.Integer;
            var originalKey  = Defaults.Guid;

            await Person_ResourcePerson_Create();

            lastKey = ResourcePersonTests.RecycleBin.LastOrDefault();

            testEntity  = new EntityReader <ResourcePerson>().GetByKey(lastKey);
            originalId  = testEntity.Id;
            originalKey = testEntity.Key;
            Assert.IsTrue(testEntity.Id != Defaults.Integer);
            Assert.IsTrue(testEntity.Key != Defaults.Guid);
            Assert.IsTrue(testEntity.CreatedDate.Date == DateTime.UtcNow.Date);

            using (var writer = new EntityWriter <ResourcePerson>(testEntity, new ResourcePersonSPConfig()))
            {
                resultEntity = await writer.DeleteAsync();
            }
            Assert.IsTrue(resultEntity.IsNew);
            Assert.IsTrue(!resultEntity.FailedRules.Any());

            testEntity = new EntityReader <ResourcePerson>().GetByKey(originalKey);
            Assert.IsTrue(testEntity.Id != originalId);
            Assert.IsTrue(testEntity.Key != originalKey);
            Assert.IsTrue(testEntity.IsNew);
            Assert.IsTrue(testEntity.Key == Defaults.Guid);
            Assert.IsTrue(!testEntity.FailedRules.Any());

            // Remove from RecycleBin (its already marked deleted)
            RecycleBin.Remove(lastKey);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Institute,Faculty,Department,Designation,Phone,Email,Specialization,SubSpecialization,Photo")] ResourcePerson resourcePerson, string pid, string FileName)
        {
            if (id != resourcePerson.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                //var traceId = Guid.NewGuid().ToString();

                // var temp = await _context.ResourcePerson.FindAsync(id);

                //if(resourcePerson.Institute==null)
                //{
                //    resourcePerson.Faculty = null;
                //    resourcePerson.Department = null;
                //}
                //if (resourcePerson.Faculty == null)
                //{
                //    resourcePerson.Department = null;
                //}
                //if(resourcePerson.Specialization==null)
                //{
                //    resourcePerson.SubSpecialization = null;
                //}

                if (pid == null)
                {
                    pid = Guid.NewGuid().ToString();
                }

                var rootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\documents\\ResourcePerson", pid);

                if (!Directory.Exists(rootPath))
                {
                    Directory.CreateDirectory(rootPath);
                }


                if (resourcePerson.Photo != null && resourcePerson.Photo.Length > 0)
                {
                    _fileService.UploadFile(resourcePerson.Photo, rootPath);

                    string temp = rootPath + "\\" + FileName;

                    _fileService.RemoveFile(temp);


                    resourcePerson.PhotoFileName = resourcePerson.Photo.FileName;
                    resourcePerson.PicFolderId   = pid;
                }
                else
                {
                    resourcePerson.PhotoFileName = FileName;
                    resourcePerson.PicFolderId   = pid;
                }


                try
                {
                    _context.Update(resourcePerson);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ResourcePersonExists(resourcePerson.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(resourcePerson));
        }
Example #13
0
        public LoginPage()
        {
            string imagesource = "eistor.png";

            NavigationPage.SetHasNavigationBar(this, false);

            var layout = new StackLayout {
                Padding = 10,
            };

            if (Device.RuntimePlatform.Equals("iOS"))
            {
                // move layout under the status bar
                layout.Padding = new Thickness(0, 20, 0, 0);
                //imagesource = "Images/app opsætning 2.jpg";
            }


            BackgroundColor = Color.White;
            Image image = new Image()
            {
                Source = imagesource, Opacity = 0.7, HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            Title = "Log ind";
            var label = new Label
            {
                Text     = "Log ind",
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalTextAlignment = TextAlignment.Center
            };

            username = new Entry {
                Placeholder = "Brugernavn"
            };


            layout.Children.Add(username);

            password = new Entry {
                Placeholder = "Password", IsPassword = true
            };
            layout.Children.Add(password);
            connectionSettingsButton = new Button {
                Text = "Opkoblingsindstillinger", BackgroundColor = Color.FromRgb(135, 206, 250), TextColor = Color.White, VerticalOptions = LayoutOptions.End
            };
            button = new Button {
                Text = "Log ind", BackgroundColor = Color.FromRgb(135, 206, 250), TextColor = Color.White, IsEnabled = false
            };
            layout.Children.Add(button);
            layout.Children.Add(connectionSettingsButton);
            layout.Children.Add(image);

            password.TextChanged += Password_TextChanged;
            username.TextChanged += Username_TextChanged;

            connectionSettingsButton.Clicked += async(s, e) =>
            {
                await Navigation.PushModalAsync(new ConnectionSettingsPage());
            };
            button.Clicked += async(s, e) =>
            {
                bool succes     = false;
                bool loading    = true;
                bool connection = false;
                while (loading)
                {
                    ActivityIndicator ai = new ActivityIndicator()
                    {
                        IsRunning = true
                    };
                    layout.Children.Add(ai);
                    button.IsEnabled = false;
                    connectionSettingsButton.IsEnabled = false;

                    try
                    {
                        person = db.GetResourcePersonAsync(username.Text.ToUpper()).Result;
                        if (person == null)
                        {
                            dbcon = false;
                            try
                            {
                                connection = await syncFacade.MaintenanceTaskSynchronizer.HasConnectionToNAV();
                            }
                            catch
                            {
                                connection = false;
                            }
                            string ss      = username.Text;
                            var    persons = await facade.ResourcePersonService.GetResroucePersons();

                            person = persons.Where(x => x.No == username.Text).FirstOrDefault();
                            //person = await facade.ResourcePersonService.GetResroucePerson(username.Text);
                        }
                        else
                        {
                            dbcon = true;
                        }
                        if (password.Text == person.Password)
                        {
                            succes = true;
                        }
                        gd.User           = person;
                        gd.SearchUserName = person.No;
                    }
                    catch
                    {
                    }
                    if (!succes && (connection || dbcon))
                    {
                        layout.Children.Remove(ai);
                        await DisplayAlert("Advarsel", "Forkert brugernavn eller password", "OK");
                    }
                    else if (!connection && !dbcon)
                    {
                        layout.Children.Remove(ai);
                        await DisplayAlert("Advarsel", "Enheden har ikke forbindelse til NAV", "OK");
                    }
                    else
                    {
                        List <Resources> rl = await db.GetResourcesAsync();

                        gd.CurrentResource = rl.Where(x => x.Name == gd.User.Name).FirstOrDefault();

                        gd.SearchDateTime     = DateTime.Today.AddDays(-7);
                        gd.SearchDateTimeLast = DateTime.Today.AddDays(7);

                        gd.TabbedPage.Children.Add(new HomePage());
                        gd.TabbedPage.Children.Add(new MeetLeavePage());
                        gd.TabbedPage.Children.Add(new MaintenancePage());
                        gd.TabbedPage.Children.Add(new SettingsPage());

                        gd.TabbedPage.Children.Remove(gd.LoginPage);
                        gd.IsLoggedIn = true;

                        password.Text = null;
                        //if (Device.OS != TargetPlatform.iOS)
                        //{
                        Task t = Task.Factory.StartNew(() => facade.ThreadManager.StartSynchronizationThread());
                        //t.Start();
                        //}
                        ConnectionSettings cs = db.GetConnectionSetting(0).Result;
                        cs.LastUser = person.No;
                        cs.lastpw   = person.Password;
                        await db.UpdateConnectionSetting(cs);
                    }
                    loading          = false;
                    button.IsEnabled = true;
                    connectionSettingsButton.IsEnabled = true;

                    layout.Children.Remove(ai);
                }
            };

            Content = new ScrollView {
                Content = layout
            };
        }
Example #14
0
        public void Person_Person_ISO8601F()
        {
            var searchChar   = "i";
            var serializer   = new JsonSerializer <ResourcePerson>();
            var resultObject = new ResourcePerson();
            var resultString = Defaults.String;
            var zeroTime     = Defaults.Date;
            var testMS       = new DateTime(1983, 12, 9, 5, 10, 20, 3);

            //Explicitly set
            serializer.DateTimeFormatString = new DateTimeFormat(DateTimeExtension.Formats.ISO8601F)
            {
                DateTimeStyles = System.Globalization.DateTimeStyles.RoundtripKind
            };

            // 1 digit millisecond
            resultObject = new ResourcePerson()
            {
                FirstName = searchChar, LastName = searchChar, BirthDate = testMS, CreatedDate = testMS, ModifiedDate = testMS
            };
            resultString = serializer.Serialize(resultObject);
            Assert.IsTrue(resultString != Defaults.String);
            Assert.IsTrue(resultString.Contains(testMS.ToString(DateTimeExtension.Formats.ISO8601F)));
            resultObject = serializer.Deserialize(resultString);
            Assert.IsTrue(resultObject.FirstName == searchChar && resultObject.LastName == searchChar);
            Assert.IsTrue(resultObject.BirthDate == testMS && resultObject.CreatedDate == testMS && resultObject.ModifiedDate == testMS);
            Assert.IsTrue(resultObject.BirthDate.Millisecond.ToString().Length == 1);

            // 2 digit millisecond
            testMS       = testMS.AddMilliseconds(-testMS.Millisecond).AddMilliseconds(30);
            resultObject = new ResourcePerson()
            {
                FirstName = searchChar, LastName = searchChar, BirthDate = testMS, CreatedDate = testMS, ModifiedDate = testMS
            };
            resultString = serializer.Serialize(resultObject);
            Assert.IsTrue(resultString != Defaults.String);
            Assert.IsTrue(resultString.Contains(testMS.ToString(DateTimeExtension.Formats.ISO8601F)));
            resultObject = serializer.Deserialize(resultString);
            Assert.IsTrue(resultObject.FirstName == searchChar && resultObject.LastName == searchChar);
            Assert.IsTrue(resultObject.BirthDate == testMS && resultObject.CreatedDate == testMS && resultObject.ModifiedDate == testMS);
            Assert.IsTrue(resultObject.BirthDate.Millisecond.ToString().Length == 2);

            // 3 digit millisecond
            testMS       = testMS.AddMilliseconds(-testMS.Millisecond).AddMilliseconds(300);
            resultObject = new ResourcePerson()
            {
                FirstName = searchChar, LastName = searchChar, BirthDate = testMS, CreatedDate = testMS, ModifiedDate = testMS
            };
            resultString = serializer.Serialize(resultObject);
            Assert.IsTrue(resultString != Defaults.String);
            Assert.IsTrue(resultString.Contains(testMS.ToString(DateTimeExtension.Formats.ISO8601F)));
            resultObject = serializer.Deserialize(resultString);
            Assert.IsTrue(resultObject.FirstName == searchChar && resultObject.LastName == searchChar);
            Assert.IsTrue(resultObject.BirthDate == testMS && resultObject.CreatedDate == testMS && resultObject.ModifiedDate == testMS);
            Assert.IsTrue(resultObject.BirthDate.Millisecond.ToString().Length == 3);

            // Mixed
            resultObject = new ResourcePerson()
            {
                FirstName = searchChar, LastName = searchChar, BirthDate = testMS.AddMilliseconds(-testMS.Millisecond), CreatedDate = testMS.AddMilliseconds(-testMS.Millisecond).AddMilliseconds(30), ModifiedDate = testMS.AddMilliseconds(-testMS.Millisecond).AddMilliseconds(300)
            };
            resultString = serializer.Serialize(resultObject);
            Assert.IsTrue(resultString != Defaults.String);
            Assert.IsTrue(resultString.Contains(testMS.ToString(DateTimeExtension.Formats.ISO8601F)));
            resultObject = serializer.Deserialize(resultString);
            Assert.IsTrue(resultObject.FirstName == searchChar && resultObject.LastName == searchChar);
            Assert.IsTrue(resultObject.BirthDate == testMS.AddMilliseconds(-testMS.Millisecond) && resultObject.CreatedDate == testMS.AddMilliseconds(-testMS.Millisecond).AddMilliseconds(30) && resultObject.ModifiedDate == testMS.AddMilliseconds(-testMS.Millisecond).AddMilliseconds(300));
            Assert.IsTrue(resultObject.BirthDate.Millisecond.ToString().Length == 1);
        }
Example #15
0
 public Task <int> DeleteResourcePersonAsync(ResourcePerson task)
 {
     return(database.DeleteAsync(task));
 }
Example #16
0
 public Task <int> SaveResourcePersonAsync(ResourcePerson task)
 {
     return(database.InsertAsync(task));
 }