示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                                                 + "was modified by another user after you got the original value. The "
                                                 + "edit operation was canceled.");
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#2
0
        public async Task <bool> EditComment(int commentId, string username, string text)
        {
            var profile = await context
                          .Profiles
                          .Include(p => p.User)
                          .FirstOrDefaultAsync(p => p.User.UserName == username);

            if (profile == null)
            {
                return(false);
            }

            var comment = await context
                          .Comments
                          .FirstOrDefaultAsync(c => c.Id == commentId && c.OwnerId == profile.Id);

            if (comment == null)
            {
                return(false);
            }

            comment.Text   = text;
            comment.isEdit = true;
            context.Update(comment);
            await context.SaveChangesAsync();

            return(true);
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text, RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", "Edited item has been modified!");
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", "komunikat informujący o tym że edytowane dane zostały zmodyfikowane lub usunięte przez innego użytkownika");
                        //throw;
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException exception)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", "Data were modified or deleted by another user!");
                        NewsItem newsItemTemp = (NewsItem)exception.Entries.Single().GetDatabaseValues().ToObject();
                        newsItem.RowVersion = newsItemTemp.RowVersion;
                        ModelState.Remove("RowVersion");
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var dbEntry = ex.Entries.Single().GetDatabaseValues();
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        var dbValues = (NewsItem)dbEntry.ToObject();
                        ModelState.AddModelError(string.Empty, "The news you tried to edit were already edited or deleted by another party!");
                        newsItem.RowVersion = (byte[])dbValues.RowVersion;
                        ModelState.Remove("RowVersion");
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "In the meantime, this news was edited by another user. You can go back or force your changes by saving them again.");
                        newsItem.RowVersion = (byte[])((NewsItem)ex.Entries.Single().GetDatabaseValues().ToObject()).RowVersion;
                        ModelState.Remove("RowVersion");

                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", "Ten wpis został usuniętu lub zmieniony przez innego użytkownika");
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsItemExists(newsItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", "The record you are trying to edit was modified or deleted by another user.");
                        return(View());
                        //throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#10
0
        public async Task <IActionResult> Edit(int id, [Bind("Text,id,TimeStamp,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsItemExists(newsItem.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        // throw;
                        ModelState.AddModelError(String.Empty, "Edited object was overwritten or deleted by another user");
                        return(View(newsItem));
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsItem));
        }
示例#11
0
        public void UpdateNewsPostSettings(string newsPostId, bool isPrivate, bool commentsAllowed = false, bool commentsModerated = false)
        {
            // NOTE: Comment Settings are not versioned, so is okay to update the model directly
            var existingNewsPost = _newsDbContext.NewsPosts.FirstOrDefault(x => x.Id == newsPostId);

            if (existingNewsPost == null)
            {
                throw new NullReferenceException($"Could not update News Post settings: Id {newsPostId} not found");
            }


            existingNewsPost.IsPrivate = isPrivate;

            // TODO - Simplify comments settings - no need for Private vs Public since
            //        "private" News posts would only be viewed by authorized users anyway
            existingNewsPost.PrivateCommentsAllowed   = commentsAllowed;
            existingNewsPost.PublicCommentsAllowed    = commentsAllowed;
            existingNewsPost.PublicCommentsModerated  = commentsModerated;
            existingNewsPost.PrivateCommentsModerated = commentsModerated;

            _newsDbContext.Update(existingNewsPost);
            _newsDbContext.SaveChanges();
        }
示例#12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,TimeStamp,Text,RowVersion")] NewsItem newsItem)
        {
            if (id != newsItem.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newsItem);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var exceptionEntry = ex.Entries.Single();
                    var databaseEntry  = exceptionEntry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError(string.Empty, "Unable to save changes. The department was deleted by another user.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "The record you attempted to edit was modified by another user."
                                                 + " If you still want to edit this record, click the Save button again.");
                        ModelState.Remove("RowVersion");
                        var dbValues = (NewsItem)databaseEntry.ToObject();
                        newsItem.RowVersion = dbValues.RowVersion;
                    }
                }
            }
            return(View(newsItem));
        }