コード例 #1
0
        public async Task <IActionResult> Edit(int id, CreateTopic_ViewModel topic)
        {
            #region Check Availability
            if (id != topic.Id)
            {
                return(NotFound());
            }
            #endregion

            #region Put Process
            if (ModelState.IsValid)
            {
                try
                {
                    #region Image Checking Process
                    if (topic.Image != null)
                    {
                        if (topic.Image.FileName != topic.ImageLink)
                        {
                            Helpers.Methods.DeleteItem(topic.ImageLink);
                        }

                        Helpers.Methods.CreateItem(topic.Image);
                    }
                    #endregion

                    #region Save New Data
                    _context.Update(CreateNewTopicObject(topic));
                    await _context.SaveChangesAsync();

                    #endregion
                }

                catch (DbUpdateConcurrencyException)
                {
                    #region Catching
                    if (!TopicExists(topic.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                    #endregion
                }
                return(RedirectToAction(nameof(Index)));
            }
            #endregion

            return(View(topic));
        }
コード例 #2
0
        public async Task <IActionResult> Create(CreateTopic_ViewModel topic)
        {
            if (topic.Type == null)
            {
                if (topic.Image != null)
                {
                    Helpers.Methods.CreateItem(topic.Image);
                }
                else
                {
                    return(NotFound());
                }


                if (ModelState.IsValid)
                {
                    _context.Add(CreateNewTopicObject(topic));
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
 private Topic CreateNewTopicObject(CreateTopic_ViewModel topic)
 {
     return(new Topic()
     {
         Id = topic.Id != default ? topic.Id : default,