public async Task <IActionResult> UpdateAsync([FromBody] TicketTypeDto model) { if (model == null) { return(NotFound()); } var currentUser = await _identityService.GetCurrentUser(); if (currentUser == null) { return(BadRequest(new { error = "You are not allowed!" })); } var person = await _identityService.GetPersonByUserId(currentUser.Id); if (person == null) { return(BadRequest(new { error = "Person was not found" })); } var ticketType = await _ticketTypeService.GetTicketTypeById(model.Id); if (ticketType == null) { return(BadRequest(new { error = "Selected ticketType was not found" })); } ticketType.Name = model.Name; ticketType.Deleted = model.Deleted; await _ticketTypeService.UpdateTicketType(ticketType); return(Ok()); }
public async Task <IActionResult> CreateTicketType([FromForm] TicketTypeCM ticketType) { try { var TicketType = new TicketType { Name = ticketType.Name, AdultPrice = ticketType.AdultPrice, ChildrenPrice = ticketType.ChildrenPrice, AtrractionId = ticketType.AtrractionId, CreateAt = DateTime.Now }; _ITicketTypeService.AddTicketType(TicketType); await _ITicketTypeService.SaveTicketType(); IList <IFormFile> imageUpload = ticketType.ImageUpload.ToList(); List <String> listImage = new List <string>(); if (imageUpload.Count > 0) { for (int i = 0; i < imageUpload.Count; i++) { var file = imageUpload[i]; var link = await _iUploadFile.uploadFile(file, TicketType.Id.ToString()); listImage.Add(link); } } TicketType.UrlImage = String.Join(";", listImage); _ITicketTypeService.UpdateTicketType(TicketType); bool result = await _ITicketTypeService.SaveTicketType(); if (!result) { return(BadRequest("Can not create TicketType")); } return(StatusCode(201, new { Id = TicketType.Id })); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult UpdateTicketType(TicketTypeRowViewModel model) { //if (!ModelState.IsValid) //{ // return BadRequest("Invalid Request"); //} var updateResult = _ticketTypeService.UpdateTicketType(model); if (!string.IsNullOrEmpty(updateResult)) { return(StatusCode((int)HttpStatusCode.NotAcceptable, updateResult)); } return(Ok()); }