Exemple #1
0
        public async Task <ServiceResponse <List <CampaignDTO> > > createCampaignAsync(CampaignDTO campaignModel)
        {
            if (campaignModel == null)
            {
                ServiceResponse <List <CampaignDTO> > serviceResponse = new ServiceResponse <List <CampaignDTO> >();
                serviceResponse.Success = false;
                serviceResponse.Message = "No model";
                return(serviceResponse);
            }

            try
            {
                var campaign = _mapper.Map <Campaign>(campaignModel);
                await _appDb.Campaigns.AddAsync(campaign);

                await _appDb.SaveChangesAsync();

                var campaigns = await _appDb.Campaigns.ToListAsync();

                var campaignsDTO = _mapper.Map <List <CampaignDTO> >(campaigns);

                ServiceResponse <List <CampaignDTO> > serviceResponse = new ServiceResponse <List <CampaignDTO> >();
                serviceResponse.Data    = campaignsDTO;
                serviceResponse.Message = "Successfully added new Campaign";
                return(serviceResponse);
            }
            catch (Exception ex)
            {
                ServiceResponse <List <CampaignDTO> > serviceResponse = new ServiceResponse <List <CampaignDTO> >();
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
                return(serviceResponse);
            }
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Keywords,Fund,Bid,Town,Status,Radius")] Campaign1 campaign1)
        {
            if (ModelState.IsValid)
            {
                _context.Add(campaign1);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(campaign1));
        }
Exemple #3
0
 public IActionResult PostCampaign(CampaignByCatCommand campaignCommand)
 {
     try
     {
         if (campaignCommand is null)
         {
             ErrorMessage.Message = "Please input data";
             return(BadRequest(ErrorMessage));
         }
         else if (campaignCommand.ListCampaignCategory.Count == 0)
         {
             ErrorMessage.Message = "Please input ProductList";
             return(BadRequest(ErrorMessage));
         }
         Campaign campaign = new Campaign();
         campaign.PromotionName   = campaignCommand.PromotionName;
         campaign.PromotionDetail = campaignCommand.PromotionDetail;
         campaign.StartDate       = campaignCommand.StartDate;
         campaign.EndDate         = campaignCommand.EndDate;
         campaign.CreatedDate     = DateTime.Now;
         campaign.PromotionType   = campaignCommand.PromotionType;
         campaign.Discount        = campaignCommand.Discount;
         campaign.ShopId          = campaignCommand.ShopId;
         campaign.IsDelete        = false;
         _context.Campaigns.Add(campaign);
         _context.SaveChangesAsync();
         List <CampaignDetailByCategory> campaignDetailByCategory = campaignCommand.ListCampaignCategory.Select(x => new CampaignDetailByCategory
         {
             CategoryId  = campaign.Id,
             CreatedDate = DateTime.Now,
             IsDelete    = false,
             CampaignsId = campaign.Id,
         }).ToList();
         foreach (var item in campaignDetailByCategory)
         {
             _context.CampaignDetailByCategory.Add(item);
         }
         _context.SaveChangesAsync();
         SucessMeassage.Message = "Sucess";
         return(Ok(SucessMeassage));
     }
     catch (Exception ex)
     {
         ErrorMessage.Message = ex.Message;
         return(StatusCode((int)HttpStatusCode.InternalServerError, ErrorMessage));
     }
 }
Exemple #4
0
 public async Task <bool> SaveChangesAsync()
 {
     return(await _context.SaveChangesAsync() > 0);
 }
Exemple #5
0
        public static void Seed(CampaignContext context)
        {
            var today        = DateTime.UtcNow;
            var creationDate = DateTime.UtcNow.AddMonths(-1);

            if (!context.Campaigns.Any())
            {
                CampaignEntities = new List <CampaignEntity>
                {
                    new CampaignEntity
                    {
                        Id                = DeletedCampaignId,
                        Name              = "DeletedCampaign",
                        Reward            = 1500,
                        CreationDate      = creationDate,
                        CompletionCount   = 1,
                        IsDeleted         = true,
                        IsEnabled         = true,
                        FromDate          = creationDate,
                        ToDate            = today.AddDays(2),
                        ConditionEntities = new List <ConditionEntity>
                        {
                            new ConditionEntity
                            {
                                BonusTypeName = BonusTypeSignUp
                            }
                        }
                    },
                    new CampaignEntity
                    {
                        Id                = ActiveCampaignId,
                        Name              = "ActiveCampaign",
                        Reward            = 1500,
                        CreationDate      = creationDate.AddDays(1),
                        FromDate          = today,
                        ToDate            = today.AddDays(2),
                        CompletionCount   = 1,
                        IsDeleted         = false,
                        IsEnabled         = true,
                        ConditionEntities = new List <ConditionEntity>
                        {
                            new ConditionEntity
                            {
                                BonusTypeName = BonusTypeSignUp
                            }
                        }
                    },
                    new CampaignEntity
                    {
                        Name            = "ActiveWithoutEndDate",
                        Reward          = 1500,
                        CreationDate    = creationDate,
                        FromDate        = today,
                        CompletionCount = 1,
                        IsDeleted       = false,
                        IsEnabled       = true
                    },
                    new CampaignEntity
                    {
                        Name            = "PendingCampaign",
                        Reward          = 1500,
                        CreationDate    = creationDate,
                        FromDate        = today.AddDays(10),
                        ToDate          = today.AddDays(15),
                        CompletionCount = 1,
                        IsDeleted       = false,
                        IsEnabled       = true
                    },
                    new CampaignEntity
                    {
                        Id              = NotEnabledCampaignId,
                        Name            = "NotEnabledCampaign",
                        Reward          = 1500,
                        CreationDate    = creationDate,
                        FromDate        = creationDate,
                        CompletionCount = 1,
                        IsDeleted       = false,
                        IsEnabled       = false
                    },
                    new CampaignEntity
                    {
                        Name            = "CompletedCampaign",
                        Reward          = 1500,
                        CreationDate    = creationDate,
                        FromDate        = creationDate,
                        ToDate          = creationDate.AddDays(2),
                        CompletionCount = 1,
                        IsDeleted       = false,
                        IsEnabled       = true
                    }
                };

                context.Campaigns.AddRange(CampaignEntities);
                context.SaveChangesAsync();
            }
        }