Ejemplo n.º 1
0
        public async Task <IWriterResult <bool> > AdminUpdateVoteItem(string userId, UpdateVoteItemModel model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var voteItem = await context.VoteItem.FirstOrDefaultNoLockAsync(x => x.Id == model.Id);

                if (voteItem == null)
                {
                    return(WriterResult <bool> .ErrorResult("VoteItem {0} not found.", model.Id));
                }

                if (model.Status == VoteItemStatus.Deleted)
                {
                    context.VoteItem.Remove(voteItem);
                }
                else
                {
                    voteItem.AdminNote   = model.Note;
                    voteItem.Name        = model.Name;
                    voteItem.Source      = model.Source;
                    voteItem.Status      = model.Status;
                    voteItem.Symbol      = model.Symbol;
                    voteItem.Website     = model.Website;
                    voteItem.AlgoType    = model.AlgoType;
                    voteItem.Description = model.Description;
                }

                var contextResults = await context.SaveChangesWithLoggingAsync();

                return(WriterResult <bool> .ContextResult(contextResults));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> AdminUpdateVoteItem(UpdateVoteItemModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("AdminUpdateVoteItemModal", model));
            }

            var result = await VoteWriter.AdminUpdateVoteItem(User.Id(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("AdminUpdateVoteItemModal", model));
            }

            return(CloseModal());
        }