public bool ImportTransactions(string fileName, User user) { var fileBody = GetFileBody(fileName); switch (Path.GetExtension(fileName)) { case ".csv": _convertStrategy = new CsvConvertToTransactionsStrategy(fileBody, user); break; default: _convertStrategy = new CsvConvertToTransactionsStrategy(fileBody, user); break; } var transactions = _convertStrategy.Convert(); if (transactions.Count > 0) { _repo.AddTransactions(transactions); } return(_repo.SaveAll()); }
public static JsonResult Delete(IFinancesRepo _repo, Controller controller, Action <IFinancesRepo> deleteAction) { try { deleteAction(_repo); if (!_repo.SaveAll()) { throw new Exception(Constants.ExceptionConstants.FailedToSave); } } catch { return(controller.Json(false)); //TODO Add logger to log ex } return(controller.Json(true)); }
public JsonResult ChangeUser([FromBody] UserViewModel vm) { try { if (ModelState.IsValid) { var user = Mapper.Map <User>(vm); _repo.ChangeUser(user, User.GetUserId()); if (_repo.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; } } } catch (Exception ex) { return(Json(false)); } return(Json(null)); }
public static JsonResult Update(IFinancesRepo _repo, Controller controller, Action <IFinancesRepo> createAction) { try { if (controller.ModelState.IsValid) { createAction(_repo); if (!_repo.SaveAll()) { throw new Exception(Constants.ExceptionConstants.FailedToSave); } } } catch (Exception ex) { return(controller.Json(false)); //TODO Add logger to log ex } return(controller.Json(true)); }