public HttpStatusCode Register(string name, string email) { if (!ModelState.IsValid) { return(HttpStatusCode.BadRequest); } if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(email)) { return(HttpStatusCode.BadRequest); } if (!email.Contains('@')) { return(HttpStatusCode.BadRequest); } try { var subscriber = new Subscriber() { EMail = email.Normalize(), Name = name }; _subscriberService.Add(subscriber, createdById: 0); return(HttpStatusCode.OK); } catch (Exception e) { return(HttpStatusCode.InternalServerError); } }
public IActionResult Add([FromForm(Name = ("subscriber"))] Subscriber subscriber) { var result = _subscriberService.Add(subscriber); if (result.Succcess) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <IActionResult> Add([FromBody] SubscriberDTO subscriber) { var outputHandler = await _service.Add(subscriber); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Created("", outputHandler.Message)); }
public IActionResult Post([FromForm] int channelId) { IDataResult <Subscriber> dataResult = _subscriberService.Add(new Subscriber { UserId = User.Claims.GetUserId().Data, ChannelId = channelId }); if (dataResult.IsSuccessful) { this.RemoveCacheByContains(User.Claims.GetUserId().Data + "/subscriptions"); this.RemoveCacheByContains(channelId + "/subscribers"); this.RemoveCacheByContains(User.Claims.GetUserId().Data + "/api/subs/issub/" + channelId); this.RemoveCacheByContains("/api/channels/" + channelId); return(Ok(dataResult.Data)); } return(this.ServerError(dataResult.Message)); }
public async Task <IActionResult> Post([FromBody] Subscriber subscriber) { try { if (!ModelState.IsValid) { _logger.LogWarning($"Error adding object with email: '{subscriber.Email}'. Detail: " + string.Join(',', ModelState.GetErrorMessages())); return(BadRequest(ModelState.GetErrorMessages())); } var result = await _subscriberService.Add(subscriber); if (!result.Success) { return(BadRequest(result.Message)); } return(CreatedAtAction("Get", new { id = result.Subscriber.Id }, result.Subscriber)); } catch (Exception ex) { _logger.LogError(ex, $"Error adding object with email: '{subscriber.Email}'"); return(BadRequest()); } }
public async Task <IActionResult> Create(SubscriberViewModel subscriber) { await _subscriberService.Add(_mapper.Map <SubscriberDto>(subscriber)); return(RedirectToAction("Index")); }