Exemplo n.º 1
0
        public async Task <IActionResult> AddProgeny(ProgenyViewModel model)
        {
            Progeny prog = new Progeny();

            prog.BirthDay    = model.BirthDay;
            prog.Admins      = model.Admins.ToUpper();
            prog.Name        = model.Name;
            prog.NickName    = model.NickName;
            prog.PictureLink = model.PictureLink;
            prog.TimeZone    = model.TimeZone;
            // Todo: Check if the progeny exists.

            if (model.File != null)
            {
                using (var stream = model.File.OpenReadStream())
                {
                    prog.PictureLink = await _imageStore.SaveImage(stream, "progeny");
                }
            }
            else
            {
                prog.PictureLink = Constants.WebAppUrl + "/photodb/childcareicon.jpg"; // Todo: Find better image
            }

            await _progenyHttpClient.AddProgeny(prog);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddProgeny()
        {
            ProgenyViewModel model       = new ProgenyViewModel();
            string           userEmail   = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser;
            UserInfo         currentUser = await _progenyHttpClient.GetUserInfo(userEmail);

            model.Admins = currentUser.UserEmail.ToUpper();

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> EditProgeny(int progenyId)
        {
            ProgenyViewModel model = new ProgenyViewModel();
            Progeny          prog  = await _progenyHttpClient.GetProgeny(progenyId);

            model.ProgenyId   = prog.Id;
            model.Name        = prog.Name;
            model.NickName    = prog.NickName;
            model.BirthDay    = prog.BirthDay;
            model.TimeZone    = prog.TimeZone;
            model.Admins      = prog.Admins.ToUpper();
            model.PictureLink = prog.PictureLink;
            if (!prog.PictureLink.ToLower().StartsWith("http"))
            {
                model.PictureLink = _imageStore.UriFor(prog.PictureLink, "progeny");
            }

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> EditProgeny(ProgenyViewModel model)
        {
            string   userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser;
            UserInfo userinfo  = await _progenyHttpClient.GetUserInfo(userEmail);

            Progeny prog = await _progenyHttpClient.GetProgeny(model.ProgenyId);

            if (!prog.IsInAdminList(userinfo.UserEmail))
            {
                // Todo: Show no access info.
                return(RedirectToAction("Index"));
            }

            prog.BirthDay = model.BirthDay;
            prog.Admins   = model.Admins.ToUpper();
            prog.Name     = model.Name;
            prog.NickName = model.NickName;
            prog.TimeZone = model.TimeZone;
            // Todo: check if fields are valid.

            if (model.File != null && model.File.Name != String.Empty)
            {
                string oldPictureLink = prog.PictureLink;
                using (var stream = model.File.OpenReadStream())
                {
                    prog.PictureLink = await _imageStore.SaveImage(stream, "progeny");
                }

                if (!oldPictureLink.ToLower().StartsWith("http") && !String.IsNullOrEmpty(oldPictureLink))
                {
                    await _imageStore.DeleteImage(oldPictureLink, "progeny");
                }
            }
            await _progenyHttpClient.UpdateProgeny(prog);

            return(RedirectToAction("Index"));
        }