예제 #1
0
        public async Task <string> AddArticle(AddArticleModel model)
        {
            var user = (User)await VirtualBD.GetFromVirtualDBAsync(User.Identity.Name);

            try
            {
                ArticleModel article = new ArticleModel();
                article.Header  = model.header;
                article.Name    = user.Name;
                article.Creator = user.Email;
                article.Viev    = 0;
                article.Type    = model.Type;
                article.Time    = DateTime.Now.ToString();
                article.Text   += $"<div class=\"row\"> <div class=\"col\">{templateMetod.Translete(model.Type)}</div> </div>";
                article.Text   += $"<div class=\"row\"> <div class=\"col\">{model.Adress} </div> </div>";
                article.Text   += model.text;

                if (model.uploadedFile != null)
                {
                    if (await templateMetod.UploadFileAsync("/Img/ArticlesImg/" + model.uploadedFile.FileName, model.uploadedFile, _appEnvironment))
                    {
                        article.Image = "/Img/ArticlesImg/" + model.uploadedFile.FileName;
                        templateMetod.CreateMinVersion(article.Image, "/Img/ArticleMinImg/" + model.uploadedFile.FileName, _appEnvironment);
                        article.ImageMin = "/Img/ArticleMinImg/" + model.uploadedFile.FileName;
                    }
                }


                db.Articles.Add(article);
                await db.SaveChangesAsync();

                VirtualBD.Articles.Add(article);
            }
            catch (Exception e)
            {
                _logger.LogError("LogError {0}", DateTime.Now.ToString() + "==>" + e.Message);
            }

            templateMetod.newEvent(db, "Добавленна статья", user.Email, user.Name, $"добавил статью:{model.header}");

            return("/Home/Index");
        }
예제 #2
0
        public async Task <string> Register(AuthorizationModel model)
        {
            User user = (User)await VirtualBD.GetFromVirtualDBAsync(model.Email);

            if (user == null)
            {
                user = new User {
                    Email = model?.Email ?? "Error", Password = model?.Password ?? "Error"
                };

                if (model.Email == null || model.Password == null)
                {
                    _logger.LogError("LogWarning {0}", DateTime.Now.ToString() + "==> Column Email or Password is empty!");
                }

                user.Role         = Role.User;
                user.RegisterData = DateTime.Now.ToString();
                user.Sex          = 0;
                user.BD           = "Неуказан";

                user.Name = model?.Name;

                if (model.uploadedFile != null)
                {
                    string patch = "/UserIcon/" + model.uploadedFile.FileName;
                    templateMetod.UploadFileAsync(patch, model.uploadedFile, _appEnvironment);
                    user.Image = patch;
                }
                else
                {
                    user.Image = "/UserDefIcon.jpg";
                }
                try
                {
                    db.Users.Add(user);
                    await db.SaveChangesAsync();

                    VirtualBD.Users.Add(user);

                    await Authenticate(user);
                }
                catch (Exception e)
                {
                    _logger.LogError("LogError {0}", DateTime.Now.ToString() + "==>" + e.Message);
                }
                templateMetod.newEvent(db, $"Зареестрирован пользователь:{model.Email}", model.Email, $"{model.Name}", "");

                return("OK");
            }
            else
            {
                return("Пользователь существует");
            }
        }