예제 #1
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("Пользователь существует");
            }
        }
예제 #2
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");
        }
예제 #3
0
        public int Send(MessageSendModel model)
        {
            MessageModel message = new MessageModel();

            if (User.Identity.IsAuthenticated)
            {
                if (model.Addressee == null)
                {
                    return(0);
                }
                else
                {
                    message.Addressee = model.Addressee;
                }

                message.Name = User.Identity.Name;
            }
            else
            {
                message.Addressee = "Admin@Admin";

                if (model.Name != null)
                {
                    message.Name = model.Name;
                }
                else
                {
                    return(0);
                }
            }

            if (model.uploadedFile != null)
            {
                templateMetod.UploadFileAsync("/Img/MessagesImg/" + model.uploadedFile.FileName, model.uploadedFile, _appEnvironment);
                message.Image = "/Img/MessagesImg/" + model.uploadedFile.FileName;
            }
            else
            {
                message.Image = null;
            }

            if (model.Header != null)
            {
                message.Header = model.Header;
            }
            else
            {
                message.Header = "Без темы";
            }

            message.Text = model.Text;
            message.Mark = false;

            message.Time   = DateTime.Now.ToString();
            message.Status = false;

            VirtualBD.Messages.Add(message);
            try
            {
                db.Messages.Add(message);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.LogError("LogError {0}", DateTime.Now.ToString() + "==>" + e.Message);
            }

            return(1);
        }