Ejemplo n.º 1
0
        public IActionResult AllPerSchool()
        {
            var principalName    = this.User.Identity.Name;
            var currentPrincipal = this.principalsRepository.AllAsNoTracking()
                                   .FirstOrDefault(x => x.User.UserName == principalName);
            var schoolId = currentPrincipal.NurserySchoolId;

            var children = this.childrenRepository.AllAsNoTrackingWithDeleted()
                           .Where(x => x.NurseryGroup.NurserySchoolId == schoolId)
                           .Select(x => new ChildViewModel
            {
                Id         = x.Id,
                FirstName  = x.FirstName,
                MiddleName = x.MiddleName,
                LastName   = x.LastName,
                CreatedOn  = x.CreatedOn,
                ModifiedOn = (System.DateTime)x.ModifiedOn,
                IsDeleted  = x.IsDeleted,
                DeletedOn  = (System.DateTime)x.DeletedOn,
            })
                           .ToList();

            var viewModel = new ChildrenViewModel
            {
                Children = children,
            };

            return(this.View(viewModel));
        }
        // GET: Friends/Edit/5
        public async Task <IActionResult> EditChild(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            //await _context.FriendViewModel.SingleOrDefaultAsync(m => m.ID == id);
            var rec = await _context.AccountUsers.SingleOrDefaultAsync(a => a.Id == id);

            ChildrenViewModel child;

            if (rec == null)
            {
                return(NotFound());
            }
            else
            {
                child = new ChildrenViewModel()
                {
                    ID              = rec.Id,
                    FirstName       = rec.FirstName,
                    MiddleName      = rec.MiddleName,
                    LastName        = rec.LastName,
                    Username        = rec.UserName,
                    Email           = rec.Email,
                    ProfilePhotoUrl = rec.PhotoUrl
                };
            }

            return(View(child));
        }
        public async Task <IActionResult> EditChild(string id, ChildrenViewModel childrenViewModel)
        {
            if (id != childrenViewModel.ID)
            {
                return(NotFound());
            }


            try
            {
                var ChildUser = _context.AccountUsers.Where(a => a.Id == id).FirstOrDefault();
                if (childrenViewModel.ProfilePicture != null)
                {
                    // Create a blob client instance.
                    CloudBlobClient blobClient = _cloudStorageAccount.CreateCloudBlobClient();

                    // Retrieve a reference to a container.
                    CloudBlobContainer container = blobClient.GetContainerReference(_blobContainerName);

                    // Create the container if it doesn't already exist.
                    await container.CreateIfNotExistsAsync();

                    await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });

                    // Retrieve reference to a blob named "myblob".
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(childrenViewModel.ProfilePicture.FileName);

                    // Upload photo to blob
                    await blockBlob.UploadFromStreamAsync(childrenViewModel.ProfilePicture.OpenReadStream());

                    // Check to see if the child has a photo url or not.
                    if (childrenViewModel.ProfilePhotoUrl != null)
                    {
                        CloudBlockBlob blobToBeDeleted = container.GetBlockBlobReference(Path.GetFileName(childrenViewModel.ProfilePhotoUrl));
                        await blobToBeDeleted.DeleteIfExistsAsync();
                    }

                    /* Automatically confirm the childs email and set the profile url.*/
                    ChildUser.PhotoUrl = string.Format("{0}", blockBlob.Uri.OriginalString);
                }

                ChildUser.FirstName  = childrenViewModel.FirstName;
                ChildUser.MiddleName = childrenViewModel.MiddleName;
                ChildUser.LastName   = childrenViewModel.LastName;
                ChildUser.UserName   = childrenViewModel.Username;
                ChildUser.Email      = childrenViewModel.Email;

                _context.Update(ChildUser);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }


            return(RedirectToAction(nameof(Children)));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Children(long menuId)
        {
            ChildrenViewModel model = new ChildrenViewModel();

            model.ParentId = menuId;
            model.NavBars  = await navbarService.GetByParentId(menuId);

            return(View(model));
        }
Ejemplo n.º 5
0
        // Util
        private ChildrenViewModel GetChildrenModel(Children children)
        {
            var model = new ChildrenViewModel
            {
                Id          = children.Id,
                FirstName   = children.FirstName,
                LastName    = children.LastName,
                DateOfBirth = children.DateOfBirth
            };

            return(model);
        }
        public async Task <IActionResult> CreateChild()
        {
            /* Get the parent profile. */
            var parent = await _userManager.GetUserAsync(User);

            if (parent == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }
            ChildrenViewModel model = new ChildrenViewModel();

            model.Email = parent.Email;
            return(View(model));
        }
Ejemplo n.º 7
0
        // GET: Children
        public async Task <ActionResult> Index(int id)
        {
            QueryCases caseRepo = new QueryCases(db);
            //PartyTypeRepository pTypeRepo = new PartyTypeRepository(db);

            string userId = User.Identity.GetUserId();

            Case aCase = await caseRepo.CaseByIdAsync(id, userId);

            ChildrenViewModel VM = new ChildrenViewModel();

            VM.CaseMenu = new CaseMenuViewModel(aCase, "Children");

            VM.Children = aCase.Children.ToList();

            return(View(VM));
        }
        // Child Regiration
        public async Task <IActionResult> ChildRegistration(ChildrenViewModel model)
        {
            try
            {
                /* Get the parent profile. */
                var parent = await _userManager.GetUserAsync(User);

                if (parent == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }

                /* Create user account. */
                var child = new ApplicationUser {
                    UserName = model.Username, Email = parent.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, IsChild = "1"
                };
                var result = await _userManager.CreateAsync(child, model.Password);

                if (result.Succeeded)
                {
                    /* Automatically confirm the childs email.*/
                    child.EmailConfirmed = true;
                    _context.AccountUsers.Update(child);
                    _context.SaveChanges();

                    /* Associate the child with their parent. */
                    var PrimaryUserAssociation = new AccountAssociations()
                    {
                        PrimaryUserID = parent.Id, AssociatedUserID = child.Id, IsChild = true
                    };
                    _context.AccountAssociations.Add(PrimaryUserAssociation);
                    _context.SaveChanges();
                }
                //}
                return(RedirectToAction(nameof(Children)));
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }
        // GET: Children
        public async Task <IActionResult> Index(SortState sortState, int page = 1)
        {
            ChildrenFilterViewModel filter = HttpContext.Session.Get <ChildrenFilterViewModel>(filterKey);

            if (filter == null)
            {
                filter = new ChildrenFilterViewModel
                {
                    FullName    = string.Empty,
                    Group       = string.Empty,
                    GroupType   = string.Empty,
                    Age         = null,
                    OtherGroups = string.Empty
                };
                HttpContext.Session.Set(filterKey, filter);
            }

            string key = $"{typeof(Child).Name}-{page}-{sortState}-{filter.FullName}-{filter.Group}-{filter.GroupType}-{filter.Age}-{filter.OtherGroups}";

            if (!_cache.TryGetValue(key, out ChildrenViewModel model))
            {
                model = new ChildrenViewModel();

                IQueryable <Child> children = GetSortedChildren(sortState, filter.FullName, filter.Group, filter.GroupType, filter.Age, filter.OtherGroups);

                int count = children.Count();

                model.PageViewModel = new PageViewModel(page, count, pageSize);

                model.Childs                  = count == 0 ? new List <Child>() : children.Skip((model.PageViewModel.PageIndex - 1) * pageSize).Take(pageSize).ToList();
                model.SortViewModel           = new SortViewModel(sortState);
                model.ChildrenFilterViewModel = filter;

                _cache.Set(key, model);
            }

            return(View(model));
        }
        public IActionResult Index()
        {
            var children = this.childrenRepository.AllAsNoTrackingWithDeleted()
                           .Select(x => new ChildViewModel
            {
                Id         = x.Id,
                FirstName  = x.FirstName,
                MiddleName = x.MiddleName,
                LastName   = x.LastName,
                CreatedOn  = x.CreatedOn,
                ModifiedOn = (System.DateTime)x.ModifiedOn,
                IsDeleted  = x.IsDeleted,
                DeletedOn  = (System.DateTime)x.DeletedOn,
            })
                           .ToList();

            var viewModel = new ChildrenViewModel
            {
                Children = children,
            };

            return(this.View(viewModel));
        }
        /* Display children list */
        private List <ChildrenViewModel> GetChildren(string ParentID)
        {
            try
            {
                List <ChildrenViewModel> retList = new List <ChildrenViewModel>();

                List <AccountAssociations> accounts = _context.AccountAssociations.Where(a => a.PrimaryUserID == ParentID && a.IsChild == true).ToList <AccountAssociations>();
                if (accounts.Count > 0)
                {
                    /* Evaluate the parents kids list.*/
                    foreach (AccountAssociations account in accounts)
                    {
                        /* Get the child's profile. */
                        var child = _context.AccountUsers.Where(b => b.Id == account.AssociatedUserID).FirstOrDefault();
                        if (child != null)
                        {
                            var childProfile = new ChildrenViewModel()
                            {
                                FirstName = child.FirstName, MiddleName = child.MiddleName, LastName = child.LastName, Username = child.UserName
                            };
                            retList.Add(childProfile);
                        }
                    }
                    return(retList);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(null);
            }
        }
        //[ValidateAntiForgeryToken]
        //[DisableFormValueModelBinding]
        public async Task <IActionResult> CreateChild(ChildrenViewModel model)
        {
            try
            {
                /* Get the parent profile. */
                var parent = await _userManager.GetUserAsync(User);

                if (parent == null)
                {
                    throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
                }

                /* Create user account. */
                var child = new ApplicationUser {
                    UserName = model.Username, Email = parent.Email, FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, IsChild = "1"
                };
                var result = await _userManager.CreateAsync(child, model.Password);

                if (result.Succeeded)
                {
                    // Create a blob client instance.
                    CloudBlobClient blobClient = _cloudStorageAccount.CreateCloudBlobClient();

                    // Retrieve a reference to a container.
                    CloudBlobContainer container = blobClient.GetContainerReference(_blobContainerName);

                    // Create the container if it doesn't already exist.
                    await container.CreateIfNotExistsAsync();

                    await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });

                    // Retrieve reference to a blob named "myblob".
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(model.ProfilePicture.FileName);

                    // Upload photo to blob
                    await blockBlob.UploadFromStreamAsync(model.ProfilePicture.OpenReadStream());

                    /* Automatically confirm the childs email and set the profile url.*/
                    child.EmailConfirmed = true;
                    child.PhotoUrl       = string.Format("{0}", blockBlob.Uri.OriginalString);
                    _context.AccountUsers.Update(child);
                    _context.SaveChanges();


                    /* Associate the child with their parent. */
                    var PrimaryUserAssociation = new AccountAssociations()
                    {
                        PrimaryUserID = parent.Id, AssociatedUserID = child.Id, IsChild = true
                    };
                    _context.AccountAssociations.Add(PrimaryUserAssociation);


                    _context.SaveChanges();
                }
                return(RedirectToAction(nameof(Children)));
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("{0} - Error Message: {1}", System.Reflection.MethodBase.GetCurrentMethod(), ex.Message));
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }