public void Setup()
 {
     log4net.Config.XmlConfigurator.Configure();
     unitOfWorkFactory = ObjectContainer.Get<UnitOfWorkFactory>();
     catRepository = ObjectContainer.Get<CatRepository>();
     ownerRepository = ObjectContainer.Get<OwnerRepository>();
 }
        internal void DeleteTestAggregate(TestAggregate aggregate)
        {
            var repository = new Repository<TestAggregate, TestEntity>();
            using (var unitOfWork = new UnitOfWorkFactory(TestSettings.BoilerMongoConfiguration).CreateUnitOfWork())
            {
                repository.UnitOfWork = unitOfWork;
                repository.Delete(aggregate);

                unitOfWork.Commit();
            }
        }
        internal void UpdateLastCreatedTestAggregateName(string name)
        {
            var repository = new Repository<TestAggregate, TestEntity>();
            using (var unitOfWork = new UnitOfWorkFactory(TestSettings.BoilerMongoConfiguration).CreateUnitOfWork())
            {
                repository.UnitOfWork = unitOfWork;
                var aggregate = repository[LastCreatedAggregateId].Value;
                aggregate.SetName(name);

                unitOfWork.Commit();
            }
        }
        internal void StoreTestAggregate(TestAggregate testAggregate)
        {
            var repository = new Repository<TestAggregate, TestEntity>();
            using (var unitOfWork = new UnitOfWorkFactory(TestSettings.BoilerMongoConfiguration).CreateUnitOfWork())
            {
                repository.UnitOfWork = unitOfWork;
                repository.Add(testAggregate);

                unitOfWork.Commit();

                LastCreatedAggregateId = testAggregate.Id;
            }
        }
        internal Optional<TestAggregate> RetrieveLastCreatedTestAggregate()
        {
            var repository = new Repository<TestAggregate, TestEntity>();
            using (var unitOfWork = new UnitOfWorkFactory(TestSettings.BoilerMongoConfiguration).CreateUnitOfWork())
            {
                repository.UnitOfWork = unitOfWork;
                var optionalAggregate = repository[LastCreatedAggregateId];
                if (!optionalAggregate.HasValue)
                {
                    return new Optional<TestAggregate>();
                }

                LastCreatedAggregateId = optionalAggregate.Value.Id;

                return optionalAggregate;
            }
        }
Esempio n. 6
0
 public TraineeDlg()
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateWithNewRoot <Trainee>();
     ConfigureDlg();
 }
Esempio n. 7
0
        public StatusCode ReceivePayment(RequestBody body)
        {
            int orderId;
            int externalId          = 0;
            SmsPaymentStatus status = SmsPaymentStatus.ReadyToSend;

            try {
                externalId = body.ExternalId;
                status     = (SmsPaymentStatus)body.Status;
                var paidDate = DateTime.Parse(body.PaidDate);

                logger.Info($"Поступил запрос на изменения статуса платежа с параметрами externalId: {externalId}, status: {status} и paidDate: {paidDate}");

                var acceptedStatuses = new[] { SmsPaymentStatus.Paid, SmsPaymentStatus.Cancelled };
                if (externalId == 0 || !acceptedStatuses.Contains(status))
                {
                    logger.Error($"Запрос на изменение статуса пришёл с неверным статусом или внешним Id (status: {status}, externalId: {externalId})");
                    return(new StatusCode(HttpStatusCode.UnsupportedMediaType));
                }

                using (IUnitOfWork uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                    SmsPayment payment;

                    try {
                        payment = uow.Session.QueryOver <SmsPayment>().Where(x => x.ExternalId == externalId).Take(1).SingleOrDefault();
                    }
                    catch (Exception e) {
                        logger.Error(e, "При загрузке платежа по externalId произошла ошибка, записываю данные файл...");
                        smsPaymentFileCache.WritePaymentCache(null, externalId);
                        return(new StatusCode(HttpStatusCode.OK));
                    }

                    if (payment == null)
                    {
                        logger.Error($"Запрос на изменение статуса платежа указывает на несуществующий платеж (externalId: {externalId})");
                        return(new StatusCode(HttpStatusCode.UnsupportedMediaType));
                    }
                    if (payment.SmsPaymentStatus == status)
                    {
                        logger.Info($"Платеж с externalId: {externalId} уже имеет актуальный статус {status}");
                        return(new StatusCode(HttpStatusCode.OK));
                    }

                    var oldStatus      = payment.SmsPaymentStatus;
                    var oldPaymentType = payment.Order.PaymentType;

                    switch (status)
                    {
                    case SmsPaymentStatus.Paid:
                        payment.SetPaid(uow, DateTime.Now, uow.GetById <PaymentFrom>(orderParametersProvider.PaymentByCardFromSmsId));
                        break;

                    case SmsPaymentStatus.Cancelled:
                        payment.SetCancelled();
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    try {
                        uow.Save(payment);
                        uow.Commit();

                        orderId = payment.Order.Id;
                        logger.Info($"Статус платежа с externalId: {payment.ExternalId} изменён c {oldStatus} на {status}");

                        #region OrderStatusChanged
                        if (oldPaymentType != payment.Order.PaymentType)
                        {
                            logger.Info(
                                $"Тип оплаты заказа № {payment.Order.Id} изменён c {oldPaymentType} на {payment.Order.PaymentType}");
                        }
                        #endregion
                    }
                    catch (Exception e) {
                        logger.Error(e, "При сохранении платежа произошла ошибка, записываю в файл...");
                        smsPaymentFileCache.WritePaymentCache(payment.Id, payment.ExternalId);
                        return(new StatusCode(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex) {
                logger.Error(ex, $"Ошибка при обработке поступившего платежа (externalId: {externalId}, status: {status})");
                return(new StatusCode(HttpStatusCode.InternalServerError));
            }

            try {
                androidDriverService.RefreshPaymentStatus(orderId);
            }
            catch (Exception ex) {
                logger.Error(ex, $"Не получилось уведомить службу водителей об обновлении статуса заказа");
            }

            return(new StatusCode(HttpStatusCode.OK));
        }
Esempio n. 8
0
 public UserService(Repository<User> userRepository, UserQueryService userQueryService, UnitOfWorkFactory unitOfWorkFactory)
 {
     _userQueryService = userQueryService;
     _unitOfWorkFactory = unitOfWorkFactory;
     _userRepository = userRepository;
 }
        public void UpdateOperations_RecalculeteDatesAfterCreateVacation()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);
            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var position1 = new StockPosition(nomenclature, 0, null, null);

                var nomenclature2 = new Nomenclature();
                nomenclature2.Type = nomenclatureType;
                uow.Save(nomenclature2);

                var protectionTools = new ProtectionTools();
                protectionTools.AddNomeclature(nomenclature);
                protectionTools.AddNomeclature(nomenclature2);
                protectionTools.Name = "СИЗ для тестирования";
                uow.Save(protectionTools);

                var position2 = new StockPosition(nomenclature2, 0, null, null);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income();
                income.Warehouse = warehouse;
                income.Date      = new DateTime(2017, 1, 1);
                income.Operation = IncomeOperations.Enter;
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense();
                expense.Warehouse = warehouse;
                expense.Employee  = employee;
                expense.Date      = new DateTime(2018, 5, 10);
                expense.Operation = ExpenseOperations.Employee;
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 10))
                            );

                //Добавляем новый отпуск на 10 дней.
                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 2, 10);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                vacation.UpdateRelatedOperations(uow, new workwear.Repository.Operations.EmployeeIssueRepository(), baseParameters, ask);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 20))
                            );
            }
        }
 public ConversationService(UnitOfWorkFactory unitOfWorkFactory)
 {
     this.unitOfWorkFactory = unitOfWorkFactory;
 }
Esempio n. 11
0
 public CommentsTemplateVM() : this(UnitOfWorkFactory.CreateWithoutRoot())
 {
 }
Esempio n. 12
0
 public EquipmentKindDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <EquipmentKind> (id);
     ConfigureDialog();
 }
Esempio n. 13
0
 public CarsDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <Car> (id);
     ConfigureDlg();
 }
Esempio n. 14
0
 public CounterpartyVM() : this(UnitOfWorkFactory.CreateWithoutRoot())
 {
     CreateRepresentationFilter = () => new CounterpartyFilter(UoW);
 }
        public virtual RefugeeOutputDto UpdateRefugee(Guid id, [FromBody] UpdateRefugeeInputDto updateRefugeeInputDto)
        {
            if (id == default(Guid))
            {
                throw new RestException(HttpStatusCode.BadRequest, Constants.Messages.InvalidIdentifier, new ArgumentException(Constants.Messages.InvalidIdentifier, nameof(id)));
            }

            if (updateRefugeeInputDto == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, Constants.Messages.MissingInputDto, new ArgumentNullException(nameof(updateRefugeeInputDto)));
            }

            if (updateRefugeeInputDto.GenderType.HasValue && !Enum.IsDefined(typeof(GenderType), updateRefugeeInputDto.GenderType))
            {
                throw new RestException(HttpStatusCode.BadRequest, "The provided gender type is not supported.", new ArgumentException("The value of the gender type is not defined in the enumeration."));
            }

            try
            {
                UpdateRefugeeInputDtoValidator.ValidateAndThrow(updateRefugeeInputDto);
            }
            catch (ValidationException exception)
            {
                throw new RestException(HttpStatusCode.BadRequest, exception.Message, exception);
            }

            RefugeeModel refugee;

            HotSpot hotSpot;

            using (IUnitOfWork unitOfWork = UnitOfWorkFactory.Create())
            {
                unitOfWork.BeginTransaction();

                refugee = unitOfWork.RefugeeRepository.GetById(id);

                if (refugee == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, Constants.Messages.ResourceCannotBeFound, new ArgumentException(Constants.Messages.ResourceCannotBeFound));
                }

                hotSpot = unitOfWork.HotSpotRepository.GetByRefugee(refugee);

                if (updateRefugeeInputDto.HotSpotId.HasValue && hotSpot.Id != updateRefugeeInputDto.HotSpotId.Value)
                {
                    hotSpot = unitOfWork.HotSpotRepository.GetById(updateRefugeeInputDto.HotSpotId.Value);

                    if (hotSpot == null)
                    {
                        throw new RestException(HttpStatusCode.NotFound, Constants.Messages.ResourceCannotBeFound, new ArgumentException(Constants.Messages.ResourceCannotBeFound));
                    }

                    unitOfWork.HotSpotRelationshipManager.UnRelate(refugee);

                    unitOfWork.HotSpotRelationshipManager.Relate(refugee, hotSpot);
                }

                if (updateRefugeeInputDto.Name != null)
                {
                    refugee.Name = updateRefugeeInputDto.Name;
                }

                if (updateRefugeeInputDto.Nationality != null)
                {
                    refugee.Nationality = updateRefugeeInputDto.Nationality;
                }

                if (updateRefugeeInputDto.Passport != null)
                {
                    refugee.Passport = updateRefugeeInputDto.Passport;
                }

                if (updateRefugeeInputDto.BirthYear.HasValue)
                {
                    refugee.BirthYear = updateRefugeeInputDto.BirthYear.Value;
                }

                if (updateRefugeeInputDto.GenderType.HasValue)
                {
                    refugee.GenderType = (GenderType)updateRefugeeInputDto.GenderType.Value;
                }

                unitOfWork.RefugeeRepository.Update(refugee);

                unitOfWork.CommitTransaction();
            }

            RefugeeOutputDto refugeeOutputDto = Mapper.Map <RefugeeModel, RefugeeOutputDto>(refugee);

            refugeeOutputDto.HotSpot = Mapper.Map <HotSpot, HotSpotOutputDto>(hotSpot);

            return(refugeeOutputDto);
        }
Esempio n. 16
0
        public async Task <Response> Edit(RemittanceEditModel model, ClaimsPrincipal User)
        {
            using (var uow = UnitOfWorkFactory.Create())
            {
                if (model == null)
                {
                    return new Response {
                               Status = StatusEnum.Error, Message = "ничего на сервер не отправлено"
                    }
                }
                ;
                if (model.Score2Id == model.ScoreId)
                {
                    return new Response {
                               Status = StatusEnum.Error, Message = "Перевод осуществляется на один и тот же счет!"
                    }
                }
                ;
                if (!uow.Scores.Check(model.ScoreId))
                {
                    return new Response {
                               Status = StatusEnum.Error, Message = $"Нет такого счета!"
                    }
                }
                ;
                if (!uow.Scores.Check(model.Score2Id))
                {
                    return new Response {
                               Status = StatusEnum.Error, Message = $"Нет такого счета!"
                    }
                }
                ;

                Score OldScore1 = null;
                Score OldScore2 = null;
                Score NewScore1 = await uow.Scores.GetByIdAsync(model.ScoreId);

                Score NewScore2 = await uow.Scores.GetByIdAsync(model.Score2Id);

                var Remittance = Mapper.Map <Remittance>(model);
                Remittance.Discriminator = "Remittance";

                var OldScoresId = uow.Remittances.GetRemmiranceScoreId(Remittance.Id);


                if (OldScoresId.Item1 != Remittance.ScoreId)
                {
                    OldScore1 = await uow.Scores.GetByIdAsync(OldScoresId.Item1);
                }

                if (OldScoresId.Item2 != Remittance.Score2Id)
                {
                    OldScore2 = await uow.Scores.GetByIdAsync(OldScoresId.Item2);
                }

                var OldSum = uow.FinanceActions.GetSumFinanceAction(Remittance.Id);

                var HelperModel = new RemittanceEditHelperModelBuilder()
                                  .SetOldScore1(OldScore1)
                                  .SetOldScore2(OldScore2)
                                  .SetNewScore1(NewScore1)
                                  .SetNewScore2(NewScore2)
                                  .SetOldTransactionSum(OldSum)
                                  .SetNewTransactionSum(Remittance.Sum)
                                  .Build();

                var Result = await CheckEditScore(HelperModel);

                if (!Result.Item1)
                {
                    return new Response {
                               Status = StatusEnum.Error, Message = Result.Item2
                    }
                }
                ;

                var _User = await UserManager.FindByNameAsync(User.Identity.Name);

                Remittance.UserId    = _User.Id;
                Remittance.ProjectId = await uow.Projects.GetNullProjectId();

                Remittance.OperationId = await uow.Operations.GetTransferOperationId();

                await uow.Remittances.UpdateAsync(Remittance);

                return(new Response {
                    Status = StatusEnum.Accept, Message = "Редактирование перевода прошло успешно."
                });
            }
        }
Esempio n. 17
0
 public RouteListCreateDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <RouteList> (id);
     ConfigureDlg();
 }
Esempio n. 18
0
 public DeliveryScheduleDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <DeliverySchedule> (id);
     ConfigureDlg();
 }
Esempio n. 19
0
 public ReadyForReceptionVM() : this(UnitOfWorkFactory.CreateWithoutRoot())
 {
 }
        public virtual GraphOutputDto GetFamiliesWithChildrenGraph()
        {
            List <FamilyRelationshipsWithHotSpots> familyRelationshipsWithHotSpots;

            int currentYear = DateTime.UtcNow.Year;

            using (IUnitOfWork unitOfWork = UnitOfWorkFactory.Create())
            {
                familyRelationshipsWithHotSpots = unitOfWork.RefugeeRepository.GetFamilyRelationshipsWithHotSpots().ToList();

                familyRelationshipsWithHotSpots.RemoveAll(o =>
                                                          ((currentYear - o.Refugee1.BirthYear) >= Properties.Settings.Default.UnderageAgeThreshold) &&
                                                          ((currentYear - o.Refugee2.BirthYear) >= Properties.Settings.Default.UnderageAgeThreshold));
            }

            IList <NodeOutputDto> nodes = new List <NodeOutputDto>();

            IList <LinkOutputDto> links = new List <LinkOutputDto>();

            #region Mapping Operations

            byte refugeeNodeType = (byte)NodeType.Refugee;

            byte hotSpotNodeType = (byte)NodeType.HotSpot;

            string livesInTypeKey = LivesInRelationship.TypeKey.ToLower();

            foreach (FamilyRelationshipsWithHotSpots familyRelationshipsWithHotSpotsData in familyRelationshipsWithHotSpots)
            {
                #region Nodes

                #region Refugees

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.Refugee1.Id, Name = familyRelationshipsWithHotSpotsData.Refugee1.Name, Type = refugeeNodeType
                });

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.Refugee2.Id, Name = familyRelationshipsWithHotSpotsData.Refugee2.Name, Type = refugeeNodeType
                });

                #endregion

                #region HotSpots

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.HotSpot1.Id, Name = familyRelationshipsWithHotSpotsData.HotSpot1.Name, Type = hotSpotNodeType
                });

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.HotSpot2.Id, Name = familyRelationshipsWithHotSpotsData.HotSpot2.Name, Type = hotSpotNodeType
                });

                #endregion

                #endregion

                #region Links

                links.Add(new LinkOutputDto {
                    SourceId = familyRelationshipsWithHotSpotsData.Refugee1.Id, TargetId = familyRelationshipsWithHotSpotsData.HotSpot1.Id, Name = livesInTypeKey
                });

                links.Add(new LinkOutputDto {
                    SourceId = familyRelationshipsWithHotSpotsData.Refugee1.Id, TargetId = familyRelationshipsWithHotSpotsData.Refugee2.Id, Name = familyRelationshipsWithHotSpotsData.IsFamilyRelationshipData1.Degree.ToString().ToLower()
                });

                links.Add(new LinkOutputDto {
                    SourceId = familyRelationshipsWithHotSpotsData.Refugee2.Id, TargetId = familyRelationshipsWithHotSpotsData.HotSpot2.Id, Name = livesInTypeKey
                });

                #endregion
            }

            nodes = nodes.DistinctBy(o => o.Id).ToList();

            #endregion

            return(new GraphOutputDto {
                Nodes = nodes, Links = links
            });
        }
Esempio n. 21
0
 public TraineeDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <Trainee>(id);
     ConfigureDlg();
 }
Esempio n. 22
0
 public FreeRentPackageDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <FreeRentPackage> (id);
     ConfigureDlg();
 }
Esempio n. 23
0
 public DeliveriesLateReport()
 {
     this.Build();
     UoW = UnitOfWorkFactory.CreateWithoutRoot();
     ySpecCmbGeographicGroup.ItemsList = UoW.GetAll <GeographicGroup>();
 }
Esempio n. 24
0
 public PaymentsFromTinkoffReport()
 {
     this.Build();
     UoW = UnitOfWorkFactory.CreateWithoutRoot();
     ConfigureDlg();
 }
Esempio n. 25
0
 public UserBO(IMapper mapper, UnitOfWorkFactory <Users> unitOfWorkFactory, IUnityContainer unityContainer)
     : base(mapper, unitOfWorkFactory)
 {
     this.unityContainer = unityContainer;
 }
Esempio n. 26
0
 public EquipmentKindDlg()
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateWithNewRoot <EquipmentKind> ();
     ConfigureDialog();
 }
Esempio n. 27
0
 public CommentDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <CommentsTemplates>(id);
     ConfigureDlg();
 }
Esempio n. 28
0
 public ConnectionTypeDlg()
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateWithNewRoot <ConnectionType> ();
     ConfigureDlg();
 }
Esempio n. 29
0
 public IncomingWaterDlg(int id)
 {
     this.Build();
     UoWGeneric = UnitOfWorkFactory.CreateForRoot <IncomingWater>(id);
     ConfigureDlg();
 }
 void UpdateUnitOfWork()
 {
     UnitOfWork = UnitOfWorkFactory.CreateUnitOfWork();
 }
Esempio n. 31
0
 public TrackMaintainer(int trackId)
 {
     uow        = UnitOfWorkFactory.CreateForRoot <Track>(trackId);
     LastActive = DateTime.Now;
 }
Esempio n. 32
0
 public BookBO(IMapper mapper, UnitOfWorkFactory <Books> unitOfWorkFactory, IUnityContainer unityContainer)
     : base(mapper, unitOfWorkFactory)
 {
     this.unityContainer = unityContainer;
 }
Esempio n. 33
0
 public RatingBO(IMapper mapper, UnitOfWorkFactory <Rating> unityOfWorkFactory, IUnityContainer unityContainer)
     : base(mapper, unityOfWorkFactory)
 {
     this.unityContainer = unityContainer;
 }
Esempio n. 34
0
        public PaymentResult RefreshPaymentStatus(int externalId)
        {
            logger.Info($"Поступил запрос на обновление статуса платежа с externalId: {externalId}");
            try {
                using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                    var payment = uow.Session.QueryOver <SmsPayment>()
                                  .Where(x => x.ExternalId == externalId)
                                  .Take(1)
                                  .SingleOrDefault();

                    if (payment == null)
                    {
                        logger.Error($"Платеж с externalId: {externalId} не найден в базе");
                        return(new PaymentResult($"Платеж с externalId: {externalId} не найден в базе"));
                    }
                    var status = paymentController.GetPaymentStatus(externalId);
                    if (status == null)
                    {
                        return(new PaymentResult($"Ошибка при получении статуса платежа с externalId: {externalId}"));
                    }

                    if (payment.SmsPaymentStatus != status)
                    {
                        var oldStatus = payment.SmsPaymentStatus;

                        switch (status.Value)
                        {
                        case SmsPaymentStatus.WaitingForPayment:
                            payment.SetWaitingForPayment();
                            break;

                        case SmsPaymentStatus.Paid:
                            payment.SetPaid(uow, DateTime.Now, uow.GetById <PaymentFrom>(orderParametersProvider.PaymentByCardFromSmsId));
                            break;

                        case SmsPaymentStatus.Cancelled:
                            payment.SetCancelled();
                            break;

                        case SmsPaymentStatus.ReadyToSend:
                            payment.SetReadyToSend();
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        uow.Save(payment);
                        uow.Commit();
                        logger.Info($"Платеж с externalId: {externalId} сменил статус с {oldStatus} на {status}");
                    }
                    else
                    {
                        logger.Info($"Платеж с externalId: {externalId} уже имеет актуальный статус {status}");
                    }

                    return(new PaymentResult(status.Value));
                }
            }
            catch (Exception ex) {
                logger.Error(ex, $"Ошибка при обновлении статуса платежа externalId: {externalId}");
                return(new PaymentResult($"Ошибка при обновлении статуса платежа externalId: {externalId}"));
            }
        }
Esempio n. 35
0
 public EquipmentKindsForRentVM()
     : this(UnitOfWorkFactory.CreateWithoutRoot())
 {
 }
		public void ConstructorTest()
		{
			var factory = new UnitOfWorkFactory();
			Assert.IsInstanceOfType(factory,typeof(UnitOfWorkFactory));
		}
        public GraphOutputDto GetRelationshipsGraph(Guid id)
        {
            if (id == default(Guid))
            {
                throw new RestException(HttpStatusCode.BadRequest, Constants.Messages.InvalidIdentifier, new ArgumentException(Constants.Messages.InvalidIdentifier, nameof(id)));
            }

            IList <FamilyRelationshipsWithHotSpots> familyRelationshipsWithHotSpots;

            using (IUnitOfWork unitOfWork = UnitOfWorkFactory.Create())
            {
                RefugeeModel refugee = unitOfWork.RefugeeRepository.GetById(id);

                if (refugee == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, Constants.Messages.ResourceCannotBeFound, new ArgumentException(Constants.Messages.ResourceCannotBeFound));
                }

                familyRelationshipsWithHotSpots = unitOfWork.RefugeeRepository.GetFamilyRelationshipsWithHotSpotsByRefugee(refugee);
            }

            IList <NodeOutputDto> nodes = new List <NodeOutputDto>();

            IList <LinkOutputDto> links = new List <LinkOutputDto>();

            #region Mapping Operations

            byte refugeeNodeType = (byte)NodeType.Refugee;

            byte hotSpotNodeType = (byte)NodeType.HotSpot;

            string livesInTypeKey = LivesInRelationship.TypeKey.ToLower();

            foreach (FamilyRelationshipsWithHotSpots familyRelationshipsWithHotSpotsData in familyRelationshipsWithHotSpots)
            {
                #region Nodes

                #region Refugees

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.Refugee1.Id, Name = familyRelationshipsWithHotSpotsData.Refugee1.Name, Type = refugeeNodeType
                });

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.Refugee2.Id, Name = familyRelationshipsWithHotSpotsData.Refugee2.Name, Type = refugeeNodeType
                });

                if (familyRelationshipsWithHotSpotsData.Refugee3 != null)
                {
                    nodes.Add(new NodeOutputDto {
                        Id = familyRelationshipsWithHotSpotsData.Refugee3.Id, Name = familyRelationshipsWithHotSpotsData.Refugee3.Name, Type = refugeeNodeType
                    });
                }

                #endregion

                #region HotSpots

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.HotSpot1.Id, Name = familyRelationshipsWithHotSpotsData.HotSpot1.Name, Type = hotSpotNodeType
                });

                nodes.Add(new NodeOutputDto {
                    Id = familyRelationshipsWithHotSpotsData.HotSpot2.Id, Name = familyRelationshipsWithHotSpotsData.HotSpot2.Name, Type = hotSpotNodeType
                });

                if (familyRelationshipsWithHotSpotsData.HotSpot3 != null)
                {
                    nodes.Add(new NodeOutputDto {
                        Id = familyRelationshipsWithHotSpotsData.HotSpot3.Id, Name = familyRelationshipsWithHotSpotsData.HotSpot3.Name, Type = hotSpotNodeType
                    });
                }

                #endregion

                #endregion

                #region Links

                links.Add(new LinkOutputDto {
                    SourceId = familyRelationshipsWithHotSpotsData.Refugee1.Id, TargetId = familyRelationshipsWithHotSpotsData.HotSpot1.Id, Name = livesInTypeKey
                });

                links.Add(new LinkOutputDto {
                    SourceId = familyRelationshipsWithHotSpotsData.Refugee1.Id, TargetId = familyRelationshipsWithHotSpotsData.Refugee2.Id, Name = familyRelationshipsWithHotSpotsData.IsFamilyRelationshipData1.Degree.ToString().ToLower()
                });

                links.Add(new LinkOutputDto {
                    SourceId = familyRelationshipsWithHotSpotsData.Refugee2.Id, TargetId = familyRelationshipsWithHotSpotsData.HotSpot2.Id, Name = livesInTypeKey
                });

                if (familyRelationshipsWithHotSpotsData.Refugee3 != null)
                {
                    links.Add(new LinkOutputDto {
                        SourceId = familyRelationshipsWithHotSpotsData.Refugee3.Id, TargetId = familyRelationshipsWithHotSpotsData.HotSpot3.Id, Name = livesInTypeKey
                    });

                    links.Add(new LinkOutputDto {
                        SourceId = familyRelationshipsWithHotSpotsData.Refugee2.Id, TargetId = familyRelationshipsWithHotSpotsData.Refugee3.Id, Name = familyRelationshipsWithHotSpotsData.IsFamilyRelationshipData2.Degree.ToString().ToLower()
                    });
                }

                #endregion
            }

            nodes = nodes.DistinctBy(o => o.Id).ToList();

            #endregion

            return(new GraphOutputDto {
                Nodes = nodes, Links = links
            });
        }