public IActionResult Create([FromBody] CampaignInputModel inputModel) { if (inputModel == null) { return(BadRequest()); } var campaign = inputModel.ToEntity(); if (!_productStore.Exists(campaign.ProductId)) { ModelState.AddModelError("Product", $"Product '{campaign.ProductId}' does not exists."); return(BadRequest(ModelState)); } campaign = _service.Create(campaign); campaign = _service.GetById(campaign.Id); if (null == campaign) { return(NoContent()); } var outputModel = CampaignOutputModel.FromEntity(campaign); return(CreatedAtRoute("ViewCampaign", new { id = outputModel.Id }, outputModel)); }
public string Execute(params object[] parameters) { if (parameters.Length < 5) { return("Invalid parameters"); } var name = parameters[0].ToString(); var productCode = parameters[1].ToString(); var duration = int.Parse(parameters[2].ToString()); var priceManipulationLimit = int.Parse(parameters[3].ToString()); var targetSalesCount = int.Parse(parameters[4].ToString()); var data = new CampaignDto { Name = name, ProductCode = productCode, Duration = duration, PriceManipulationLimit = priceManipulationLimit, TargetSalesCount = targetSalesCount }; var response = _campaignService.Create(data); if (response.Success) { return ($"Campaign created; name {data.Name}, product {data.ProductCode}, duration {data.Duration}, limit {data.PriceManipulationLimit}, target sales count {data.TargetSalesCount}"); } return(string.Empty); }
public IActionResult Create(Campaign campaign) { if (campaign == null) { return(BadRequest()); } var result = _campaignService.Create(campaign); return(Ok(result)); }
private Campaign CreateCampaign(CampaignDto campaign, Goal goal) { var _campaign = _campaignService.Create( campaign.CampaignName, campaign.CampaignDescription, campaign.CampaignUrl, goal ); return(_campaign.Entity); }
public ActionResult Create(CampaignDTO campaign) { var newId = _campaigns.Create(campaign); if (newId == -1) { return(BadRequest()); } return(CreatedAtAction(nameof(Get), new { id = newId })); }
public ActionResult Save(CampaignViewModel data) { string username = User.Identity.GetUserName(); CommonView model = new CommonView(); string message = string.Empty; try { if (data.ID == 0) { CampaignViewModel campaign = new CampaignViewModel(); //add data.CreatedBy = username; data.DateCreated = DateTime.Now; data.SiteID = 0; campaign = _campaignService.Create(data); if (campaign.ID > 0) { message = "Data added."; data.ID = campaign.ID; } } else { //update data.DateModified = DateTime.Now; data.ModifiedBy = username; data.SiteID = 0; _campaignService.Update(data); message = "Data updated."; } _siteCampaignService.Create(data.ID, data.SiteIDs); model.Message = message; } catch (Exception ex) { if (ex.GetType() == typeof(ArgumentException)) { model.Message = ((ArgumentException)ex).Message; } else { model.Message = "Unable to save data. Please contact your system administrator."; } } return(Json(model, JsonRequestBehavior.AllowGet)); }
public Campaign Create(Campaign baseEntity, string username) { using (var transaction = new TransactionScope()) { var campaign = _campaignService.Create(baseEntity, username); var dealerships = _dealership.Relate(baseEntity.Dealerships, campaign.Id, username); campaign.Dealerships = dealerships; transaction.Complete(); return(campaign); } }
public void Should_Create() { Campaign campaign = new Campaign { ProductCode = "P1", Name = "C1", Duration = 5, PriceManupilationLimit = 20, TargetSalesCount = 100, Status = true }; var result = _campaignService.Create(campaign); Assert.IsNotNull(result); Assert.Equals(1, result.Count()); }
public ModelHandlerResult Handle(CreateCampaignModel model) { var data = new CreateCampaignModel(); var result = _CampaignService.Create(new CreateCampaignInputModel { ID_Login = _loggedUser.ID_Login, DisplayName = model.DisplayName, Description = model.Description, ID = model.Id, }); return(new ModelHandlerResult() { Message = result.IsSuccess ? Resources.Dictionary.Global_Create_SuccessNotification : null, Data = model, Exception = result.Exception, ValidationMessages = result.ValidationMessages }); }
private void addCampaignButton_Click(object sender, EventArgs e) { var camapignForm = new CampaignForm(null); StyleManager.Clone(camapignForm); if (camapignForm.ShowDialog(this) == DialogResult.OK) { //guardar la campaña try { iCampaignService.Create(camapignForm.iCampaignModel); MetroMessageBox.Show(this, "a partir de ahora la campaña creada estara disponible en el sistema", "Exito al crear la campaña", MessageBoxButtons.OK, MessageBoxIcon.Question); reloadSearch(); } catch (Exception ex) { MetroMessageBox.Show(this, "detalles del error: " + ex.Message, "Error al crear la campaña", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public IActionResult Create([FromForm] CampaignInputModel inputModel) { if (!ModelState.IsValid) { ViewData["ProductId"] = new SelectList(_productStore.List(), "Id", "Name"); return(View(inputModel)); } var campaign = inputModel.ToEntity(); if (!_productStore.Exists(campaign.ProductId)) { ModelState.AddModelError("Product", $"Product '{campaign.ProductId}' does not exists."); return(BadRequest(ModelState)); } campaign = _service.Create(campaign); var outputModel = CampaignOutputModel.FromEntity(campaign); return(RedirectToAction(nameof(Index))); }