Пример #1
0
        public async Task <IActionResult> UpdateLisdo(Lisdo lisdo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            string uId = await GetCurrentUserId();

            var result = await _repo.UpdateLisdo(lisdo, uId);

            if (result)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Пример #2
0
        public async Task <bool> UpdateLisdo(Lisdo lisdo, string uId)
        {
            if (lisdo.IsNew)
            {
                _context.Lisdos.Add(lisdo);
                await _context.SaveChangesAsync();

                return(true);
            }
            else
            {
                var ltu = await(from ld in _context.Lisdos
                                where ld.Id == lisdo.Id
                                select new Lisdo
                {
                    Id          = ld.Id,
                    AuthorId    = ld.AuthorId,
                    Description = ld.Description,
                    Items       = ld.Items,
                    Name        = ld.Name,
                    Priority    = ld.Priority,
                    TeamId      = ld.TeamId,
                    Type        = ld.Type,
                    UpvoteCount = ld.UpvoteCount,
                    AuthorName  = ld.AuthorName
                }).SingleOrDefaultAsync();

                if (ltu.AuthorId == uId)
                {
                    ltu.Name        = lisdo.Name;
                    ltu.Description = lisdo.Description;
                    ltu.Type        = lisdo.Type;
                    ltu.Priority    = lisdo.Priority;
                    await _context.SaveChangesAsync();

                    return(true);
                }
            }

            return(false);
        }