示例#1
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model)
        {
            ViewBag.Title = "ДУБ - Смена пароля";
            if (!ModelState.IsValid)
            {
                return(View());
            }
            if (!await CheckEmail(model.Email))
            {
                ModelState.AddModelError("Email", "Электронная почта не найдена!");
                return(View());
            }

            var autor = await _oak.Autors.FirstAsync(m => m.Email == model.Email);

            autor.Code = GenerateCode();
            await _oak.SaveChangesAsync();

            SendCode(autor);

            HttpContext.Session.Set("Autor", Encoding.UTF8.GetBytes(autor.Email));


            return(View("Code"));
        }
示例#2
0
        public async Task <IActionResult> Article(long?id)
        {
            var model = await _oak.Articles.FirstOrDefaultAsync(m => m.ID == id);

            if (model is null)
            {
                return(RedirectToAction("Error", "Articles"));
            }

            await _oak.Entry(model).Reference(m => m.Autor).LoadAsync();

            await _oak.Entry(model).Reference(m => m.Section).LoadAsync();

            await _oak.Entry(model).Collection(m => m.ArtTexts).LoadAsync();

            await _oak.Entry(model).Collection(m => m.ArtSubtitles).LoadAsync();

            await _oak.Entry(model).Collection(m => m.ArtImages).LoadAsync();

            List <(string Type, short Number, byte[] Data)> content = new List <(string Type, short Number, byte[] Data)>();

            content.AddRange(model.ArtTexts.Select(at => ("text", at.Number, at.Text)));
            content.AddRange(model.ArtSubtitles.Select(at => ("sub", at.Number, at.Subtitle)));
            content.AddRange(model.ArtImages.Select(at => ("img", at.Number, at.Image)));
            ViewBag.Content = content.OrderBy(e => e.Number).ToList();

            model.Views++;
            await _oak.SaveChangesAsync();

            ViewBag.Title = $"Статья - {model.Name}";
            return(View(model));
        }