Beispiel #1
0
        public SaveTODOResponse Update(UpdateTODO request)
        {
            var ret = new SaveTODOResponse();

            var item = GetActualForUser(request.UserId)
                       .SingleOrDefault(x => x.PublicId == request.PublicId);

            if (item == null)
            {
                ret.SetError($"Item with id {request.PublicId} not found");
            }
            else
            {
                item.Title       = request.Title;
                item.Description = request.Description;
                item.Updated     = DateTime.UtcNow;

                try
                {
                    _dbContext.SaveChanges();

                    item = GetActualForUser(request.UserId)
                           .SingleOrDefault(x => x.PublicId == request.PublicId);
                }
                catch (Exception e)
                {
                    ret.SetError(e.Message);
                    return(ret);
                }

                ret.Data = _mapper.Map <TodoPublicEntity>(item);
            }
            return(ret);
        }
Beispiel #2
0
        public SaveTODOResponse Create(CreateTODO request)
        {
            var ret = new SaveTODOResponse();

            if (request.PublicId == Guid.Empty)
            {
                ret.SetError("PublicId must be pregenerated");
                return(ret);
            }

            if (request.UserId == Guid.Empty)
            {
                ret.SetError("Security violation - UserId is empty");
                return(ret);
            }

            try
            {
                var newItem = _dbContext.Todos.Add(new TodoEntity()
                {
                    PublicId    = request.PublicId,
                    UserId      = request.UserId,
                    Title       = request.Title,
                    Description = request.Description,
                    IsDeleted   = false,
                    Created     = DateTime.UtcNow,
                    Updated     = DateTime.UtcNow,
                });
                _dbContext.SaveChanges();

                ret.Data = _mapper.Map <TodoPublicEntity>(newItem.Entity);
            }
            catch (Exception e)
            {
                ret.SetError("Can`t create - " + e.Message);
            }

            return(ret);
        }