public async Task CreateOfferAsync(OfferHelpFormInputModel input, [CallerMemberName] string callerMethodName = "")
        {
            var helpTask = new HelpTask
            {
                Title       = input.Title,
                Description = input.Description,
                Location    = input.Location,
                ImageName   = input.ImageName,
                Type        = input.TaskType,
                Creator     = input.Creator,
            };

            // get selected items by their id's.
            var availableItems = this.itemService.GetAll().Where(i => input.AvailableItemsId.Contains(i.Id)).ToList();

            // add available items to database.
            foreach (var item in availableItems)
            {
                helpTask.Items.Add(new HelpTaskItems()
                {
                    ItemId      = item.Id,
                    ItemUseType = ItemUseType.Available,
                });
            }

            await this.helpTaskRepo.AddAsync(helpTask);

            await this.helpTaskRepo.SaveChangesAsync();
        }
Beispiel #2
0
        public void HelpLogsHelp()
        {
            ITaskRegistry registry = Substitute.For <ITaskRegistry>();
            HelpTask      task     = new HelpTask(registry, "GeneralHelp");

            ITaskInteraction interaction = Substitute.For <ITaskInteraction>();
            ILoggers         loggers     = Substitute.For <ILoggers>();

            interaction.Loggers.Returns(loggers);
            ILogger logger = Substitute.For <ILogger>();

            loggers[LoggerType.Result].Returns(logger);

            task.Execute(interaction).Should().Be(ExitCode.Success);
            logger.Received().WriteLine(WriteStyle.Fixed, "GeneralHelp");
        }
Beispiel #3
0
 public OperationResult <HelpTask> Post([FromBody] HelpTask value)
 {
     if (ModelState.IsValid)
     {
         var oldtask = context.HelpTasks.FirstOrDefault(x => x.PhoneSerialNumber == value.PhoneSerialNumber &&
                                                        x.Status == HelpTaskStatus.Open);
         if (oldtask == null)
         {
             value.Status = HelpTaskStatus.Open;
             var result = context.HelpTasks.Add(value);
             context.SaveChanges();
             return(OperationResult.Ok(result.Entity));
         }
         else
         {
             return(OperationResult.Fail <HelpTask>("У пользователя уже есть запрос"));
         }
     }
     else
     {
         return(OperationResult.Fail <HelpTask>("Модель не валидный"));
     }
 }