コード例 #1
0
        public async Task <ActionResult <List <int> > > AddNewsForTeachers([FromBody] NewsInputModel model)
        {
            List <int> newsIds = new List <int>();

            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            if (model.GroupID != null)
            {
                model.GroupID = null;
            }

            List <User> teachers = await userStorage.GetUserByRoleId(teacherRoleId);

            foreach (var user in teachers)
            {
                model.RecipientID = user.Id;
                newsIds.Add(await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model)));
            }
            if (newsIds.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }
            return(Ok(newsIds));
        }
コード例 #2
0
        public async Task <ActionResult <int> > AddNewsForAll([FromBody] NewsInputModel model)
        {
            var newsId = 0;

            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            if (model.RecipientID != null)
            {
                model.RecipientID = null;
            }
            if (model.GroupID != null)
            {
                model.GroupID = null;
            }

            newsId = await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model));

            if (newsId.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }
            return(Ok(newsId));
        }
コード例 #3
0
        public async Task <ActionResult <int> > AddNewsForGpoup([FromBody] NewsInputModel model)
        {
            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            if (model.RecipientID != null)
            {
                model.RecipientID = null;
            }
            if (model.GroupID == null)
            {
                return(BadRequest("The inputModel doesn't contain GroupID"));
            }

            var  newsId = 0;
            bool isCreationAllowed;

            isCreationAllowed = await groupStorage.GetBelongnessOfGroupToTheTeacher((int)model.GroupID,
                                                                                    model.AuthorId);

            if (isCreationAllowed && await CanUserPost(model.AuthorId))
            {
                newsId = await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model));
            }
            if (newsId.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }
            return(Ok(newsId));
        }
コード例 #4
0
        public async Task EditNews(NewsInputModel inputModel)
        {
            News news = this.mapper.Map <News>(inputModel);

            this.context.News.Update(news);
            await this.context.SaveChangesAsync();
        }
コード例 #5
0
        public async Task AddNews(NewsInputModel inputModel)
        {
            News news = this.mapper.Map <News>(inputModel);

            await this.context.News.AddAsync(news);

            await this.context.SaveChangesAsync();
        }
コード例 #6
0
        private NewsInputModel ProvideInputData()
        {
            var data = new NewsInputModel()
            {
                ID = Guid.NewGuid(), NrIntern = "Test", Description = "Test2", Title = "Test"
            };

            return(data);
        }
コード例 #7
0
ファイル: UpdateRecord.cs プロジェクト: mybirthname/ERPFinal
        private NewsInputModel GetInputModel(Guid id)
        {
            var model = new NewsInputModel()
            {
                ID = id, NrIntern = "Test Change", Title = "Test Change"
            };

            return(model);
        }
コード例 #8
0
ファイル: NewsService.cs プロジェクト: mybirthname/ERPFinal
        public async Task CreateNewsRecord(NewsInputModel model)
        {
            var instance = this.Mapper.Map <News>(model);

            SetBaseModelFieldsOnCreate(instance);

            await DbContext.News.AddAsync(instance);

            await DbContext.SaveChangesAsync();
        }
コード例 #9
0
        public void ShouldMapCreateNewsRouteWithCorrentData()
        {
            string newsContent = "News Content";
            string newsTitle = "News Title";
            var model = new NewsInputModel() { Content = newsContent, Title = newsTitle };

            this.routeCollection.ShouldMap("/Public/News/Create")
                .WithFormUrlBody($"Content={ newsContent }&Title={ newsTitle }")
                .To<NewsController>(c => c.Create(model));
        }
コード例 #10
0
ファイル: NewsService.cs プロジェクト: mybirthname/ERPFinal
        public async Task UpdateRecord(NewsInputModel model)
        {
            var news = await DbContext.News.FirstOrDefaultAsync(m => m.ID == model.ID);

            Mapper.Map <NewsInputModel, News>(model, news);

            SetBaseModelFieldOnUpdate(news);

            DbContext.Attach(news).State = EntityState.Modified;
            await DbContext.SaveChangesAsync();
        }
コード例 #11
0
ファイル: NewsController.cs プロジェクト: idukic/b-kind
        public async Task <IActionResult> Edit(int?id)
        {
            var model = new NewsInputModel {
                News = new Model.News()
            };

            if (id.HasValue)
            {
                model.News = await _mediator.Send(new GetByIdQuery <Model.News>(id.Value));
            }

            return(View(model));
        }
コード例 #12
0
        public async Task <IActionResult> Edit(NewsInputModel newsInput)
        {
            try
            {
                var newsItem = this.mapper.Map <News>(newsInput);
                await this.newsService.EditNews(newsItem);

                return(this.Redirect(nameof(this.GetAll)));
            }
            catch (Exception ex)
            {
                return(this.View("Error"));
            }
        }
コード例 #13
0
        public async Task <ActionResult <int> > AddOrUpdateNews([FromBody] NewsInputModel model)
        {
            if (model == null)
            {
                return(BadRequest("Model is empty"));
            }
            var newsId = await newsStorage.NewsAddOrUpdate(NewsMapper.ToDataModel(model));

            if (newsId.Equals(null))
            {
                return(BadRequest("Failed to add object"));
            }

            return(Ok(newsId));
        }
コード例 #14
0
ファイル: AdminController.cs プロジェクト: razsilev/Sv_Naum
        public ActionResult NewsAdd(NewsInputModel inputNews)
        {
            if (this.ModelState.IsValid)
            {
                var newsSingleDb = new NewsSingle();

                newsSingleDb.Content = this.sanitizer.Sanitize(inputNews.Content);

                this.Repo.Insert(this.Context.News, newsSingleDb);

                return(RedirectToAction("Index", "Home"));
            }

            return(View(inputNews));
        }
コード例 #15
0
        public static News ToDataModel(NewsInputModel news)
        {
            var result = new News
            {
                Id              = news.Id,
                Title           = news.Title,
                Content         = news.Content,
                PublicationDate = Convert.ToDateTime(news.PublicationDate),
                AuthorId        = news.AuthorId,
                RecipientID     = news.RecipientID,
                GroupID         = news.GroupID
            };

            return(result);
        }
コード例 #16
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            InputModel = await _service.GetNewsByID(id.Value);

            if (InputModel == null)
            {
                return(NotFound());
            }

            return(Page());
        }
コード例 #17
0
ファイル: NewsController.cs プロジェクト: idukic/b-kind
        public async Task <IActionResult> Edit(NewsInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await _mediator.Send(model);

            if (result.HasErrors)
            {
                MapToModelState(result);
                return(View(model));
            }

            return(Redirect("/"));
        }
コード例 #18
0
        public ActionResult Create(NewsInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            if (model.File != null)
            {
                model.PhotoPath = new NewsImageUploader().Save(this.Server, model.File);
            }

            var databaseNews = this.Mapper.Map<News>(model);
            databaseNews.CreatedOn = DateTime.Now;
            int id = this.newsService.Create(databaseNews);

            return this.RedirectToAction("Details", "News", new { id = id, name = model.Title.ToUrl() });
        }
コード例 #19
0
        public async Task <IActionResult> CreateNews(NewsInputModel newsInput)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(newsInput));
            }

            try
            {
                var newsItem = this.mapper.Map <News>(newsInput);
                await this.newsService.Create(newsItem);

                return(this.Redirect(nameof(this.GetAll)));
            }
            catch (Exception ex)
            {
                return(this.View("Error"));
            }
        }
コード例 #20
0
        public ActionResult PostNews(NewsInputModel model)
        {
            if (ModelState.IsValid)
            {
                var news = new News()
                {
                    Title   = model.Title,
                    Content = sanitizer.Sanitize(model.Content),
                    User    = this.User
                };

                base.Data.News.Add(news);

                base.Data.News.SaveChanges();
                return(this.RedirectToAction("Details", "News", new { area = "", news.Id }));
            }

            return(this.View(model));
        }
コード例 #21
0
        public async Task <Response <Model.News> > Handle(NewsInputModel message)
        {
            var response = new Response <Model.News>();

            Model.News news = null;

            news = message.News.Id > 0
                ? await _mediator.Send(new GetByIdQuery <Model.News>(message.News.Id))
                : new Model.News();

            news.Published = DateTime.UtcNow;
            news.Title     = message.News.Title;
            news.Content   = message.News.Content;
            news.Link      = message.News.Link;
            news.Slug      = message.News.Title.GenerateSlug();

            if (news.Id > 0)
            {
                _uow.Update(news);
            }
            else
            {
                _uow.Add(news);
            }


            try
            {
                await _uow.Commit();

                response.Result = news;
            }
            catch (Exception e)
            {
                response.AddError("", e.Unwrap().Message);
            }

            return(response);
        }
コード例 #22
0
        public async Task <IActionResult> Create()
        {
            var newsModel = new NewsInputModel();

            return(this.View(newsModel));
        }
コード例 #23
0
        public ActionResult PostNews()
        {
            var model = new NewsInputModel();

            return(this.View(model));
        }
コード例 #24
0
        public async Task <IActionResult> Edit(NewsInputModel inputModel)
        {
            await this.newsService.EditNews(inputModel);

            return(this.RedirectToAction("Index"));
        }
コード例 #25
0
        public async Task <IActionResult> Edit(int id)
        {
            NewsInputModel inputModel = await this.newsService.GetNewsModelById <NewsInputModel>(id);

            return(this.View(inputModel));
        }
コード例 #26
0
ファイル: frmAddNews.cs プロジェクト: TheDoomKing/BTM
        private async void BtnAdd_Click(object sender, EventArgs e)
        {
            if (txtTitle.Text == "" || txtArticle.Text == "" || txtDescription.Text == "")
            {
                MessageBox.Show("Please add a title and description!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Logo == null || Render == null)
            {
                MessageBox.Show("You must upload a logo and a render!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int logoWidth  = Logo.Width;
            int logoHeight = Logo.Height;

            if (!(logoWidth == 256 && logoHeight == 256))
            {
                MessageBox.Show("The logo's resolution must be 256x256px!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int renderWidth  = Render.Width;
            int renderHeight = Render.Height;

            if (!(renderWidth == 1920 && renderHeight == 1080))
            {
                MessageBox.Show("The render must be in Full HD (1920x1080px)!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Models.User submitter = await $"{Properties.Settings.Default.APIUrl}/users/userid/{APIService.Username}".GetJsonAsync <Models.User>();

            if (submitter == null)
            {
                MessageBox.Show("Your user ID is invalid!", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var model = new NewsInputModel
            {
                Title       = txtTitle.Text,
                Description = txtDescription.Text,
                Content     = txtArticle.Text,
                DateAdded   = DateTime.Now,
                UserID      = submitter.Id
            };

            string News  = await $"{Properties.Settings.Default.APIUrl}/info/news".GetStringAsync();
            string Logos = await $"{Properties.Settings.Default.APIUrl}/info/news/logos".GetStringAsync();

            string RenderFileName = Path.GetFileName(RenderDialog.FileName);
            string LogoFileName   = Path.GetFileName(LogoDialog.FileName);

            try
            {
                System.IO.File.Copy(RenderDialog.FileName, $@"{News}\{RenderFileName}");
                System.IO.File.Copy(LogoDialog.FileName, $@"{Logos}\{LogoFileName}");
            }
            catch { }

            model.Logo  = $"/Assets/News/{LogoFileName}";
            model.Image = $"/Assets/News/Logos/{RenderFileName}";

            try
            {
                var returns = await _newsService.Insert <dynamic>(model);

                MessageBox.Show("News article added successfully", "Success",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }