Пример #1
0
        public ServiceResult Add(ObjFinance objFinance)
        {
            try
            {
                var finance = Map(objFinance);
                _financeRepository.Insert(finance);
                _financeRepository.SaveChanges();
                _logger.LogDebug("Save Finance");

                if (finance.FinanceType == FinanceTypes.Expence)
                {
                    //проверяем на принадлежность к пользователю
                    if (finance.UserId != null)
                    {
                        var participant = _participantRepository.Get(finance.UserId.Value, finance.ProjectId, RootTypes.Project);
                        if (participant == null)
                        {
                            return(ServiceResult.ErrorResult("Добавьте участника"));
                        }

                        participant.Residue -= finance.Cost * CurrencyConverter.ConvertValute(finance.Currency, participant.Currency);

                        _participantRepository.Update(participant);
                        _participantRepository.SaveChanges();
                        _logger.LogDebug("Save participant");
                    }
                }
                //для поступления только один вариант
                if (finance.FinanceType == FinanceTypes.Receipt)
                {
                    var project = _projectRepository.Get(finance.ProjectId);
                    if (project == null)
                    {
                        return(ServiceResult.ErrorResult("Проект не найден"));
                    }
                    int ClientId = project.RootId;
                    var client   = _clientRepository.Get(ClientId);
                    if (client == null)
                    {
                        return(ServiceResult.ErrorResult("Клиент не найден"));
                    }

                    project.Residue -= finance.Cost * CurrencyConverter.ConvertValute(finance.Currency, project.Currency);
                    _projectRepository.Update(project);
                    _projectRepository.SaveChanges();
                    _logger.LogDebug("Save project");

                    client.Credit -= finance.Cost * CurrencyConverter.ConvertValute(finance.Currency, CurrencyType.Rub);
                    _clientRepository.Update(client);
                    _clientRepository.SaveChanges();
                    _logger.LogDebug("Save Client");
                }
                return(ServiceResult.SuccessResult());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return(ServiceResult.ErrorResult("Ошибка сохранения"));
            }
        }
Пример #2
0
        public IActionResult AddFinance(ObjFinance objFinance)
        {
            objFinance.CreatedId = _userService.GetUserByEmail(HttpContext.User.Identity.Name).Id;
            var result = _financeService.Add(objFinance);

            if (result.Success)
            {
                return(RedirectToAction("GetFinancesList", new { rootId = objFinance.RootId, rootType = objFinance.RootType }));
            }
            return(Json(result));
        }
Пример #3
0
        public Finance Map(ObjFinance obj)
        {
            return(new Finance()
            {
                Id = obj.Id,
                FinanceType = obj.FinanceType,

                SubTypeId = obj.SubTypeId,
                ProjectId = obj.ProjectId,
                Date = obj.Date,
                Place = obj.Place,

                Cost = obj.Cost,
                Currency = obj.Currency,

                UserId = obj.UserId,

                DocumentName = obj.DocumentName
            });
        }