public async Task <GetTaskResponse> GetTaskDetails([FromQuery] long id) { try { #region validation if (id == 0) { throw ToDoExceptions.CreateExceptionRequiredFieldIsMissing(nameof(id)); } #endregion return(await _getTaskService.GetTaskAsync(id)); } catch (BaseException ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; // debug RedisProvider _redis = new RedisProvider(); _redis.Set <BaseException>("last-exception", ex); /// return(null); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(null); } }
public async Task <ToDoTask> ChangeTaskStatusAsync(long id) { RedisProvider _redis = new RedisProvider(); //todo rename with ctrl + R + R var _key = $"{Constants.TASK_PREFIX}{Convert.ToString(id)}"; var _data = _redis.Get <ToDoTask>(_key); _data.IsDone = !(_data.IsDone); _redis.Set(_key, _data); return(_data); }
public async Task <ToDoTask> AddTask([FromBody] AddTaskParams parameters) { try { #region validation if (parameters == null) { throw ToDoExceptions.CreateExceptionBadParam(nameof(parameters), "null", "Parameters is null"); } if (parameters.Id == 0) { throw ToDoExceptions.CreateExceptionRequiredFieldIsMissing(nameof(parameters.Id)); } if (parameters.Name == null) { throw ToDoExceptions.CreateExceptionRequiredFieldIsMissing(nameof(parameters.Name)); } #endregion return(await _postTaskService.AddTaskAsync( parameters.Id, parameters.Name, parameters.Description)); } catch (BaseException ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; // debug RedisProvider _redis = new RedisProvider(); _redis.Set <BaseException>("last-exception", ex); /// return(null); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(null); } }
public async Task <ToDoTask> AddTaskAsync( long id, string name, string description) { RedisProvider _redis = new RedisProvider(); var _task = new ToDoTask { Id = id, Name = name, Description = description }; var key = $"{Constants.TASK_PREFIX}{ Convert.ToString(id) }"; _redis.Set(key, _task); return(_task); }
public async Task <Cart> AddToCartAsync(long product, string userId) { Random random = new Random(); var userCart = await _redisProvider.Get <Cart>(string.Format(Constants.USER_CART_INFO, userId)); if (userCart == null) { userCart = new Cart { Products = new List <Product>(), Id = random.Next(0, 1000) } } ; var currentProduct = await _product.GetAsync(product.ToString()); userCart.Products.Add(currentProduct); await _redisProvider.Set(string.Format(Constants.USER_CART_INFO, userId), userCart, TimeSpan.FromDays(3)); return(userCart); }
public async Task DeleteTask(long id) { // Todo: fix api. case: if there is nothing to delete try { if (id == 0) { throw ToDoExceptions.CreateExceptionBadParam(nameof(id), id.ToString()); } await _deleteTaskService.DeleteTask(id); } catch (BaseException ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; // debug RedisProvider _redis = new RedisProvider(); _redis.Set <BaseException>("last-exception", ex); /// } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; } }