Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }