public IHttpActionResult UpdateCampaign(AddUpdateCampaignViewModel campaign) { Guard.NotNull(campaign, nameof(campaign)); Guard.NotNullOrEmpty(campaign.Title, "Campaing title is null"); if (!DateTime.TryParse(campaign.FromDate.Value.ToString(), out DateTime from)) { throw new Exception("Invalid Date Time Format in Campaign From Date."); } if (!DateTime.TryParse(campaign.ToDate.Value.ToString(), out DateTime to)) { throw new Exception("Invalid Date Time Format in Campaign To Date."); } if (to <= from) { throw new Exception("Campaign To Date must be greater than Campaign From Date.,"); } if (!Enum.IsDefined(typeof(GlobalEnum.Target), campaign.Target)) { throw new Exception("Invalid Target for campaign.,"); } var map = AutoMapper.Mapper.Map <Campaign>(campaign); var result = _serviceFactory.CreateCampaignService.InsertOrUpdateCampaign(map); return(Ok(result)); }
public IHttpActionResult DeleteCampaign(AddUpdateCampaignViewModel campaign) { Guard.NotDefault(campaign.Id, "Campaign Id null.,"); var map = AutoMapper.Mapper.Map <Campaign>(campaign); map.UpdatedBy = 1; var result = _serviceFactory.CreateCampaignService.DeleteCampaign(map); return(Ok(result)); }