public async Task <IActionResult> PostRegistration(CreateRegistrationRequest request) { var existingRegistration = await _registrationService.GetByUserAndWorkshopIds(request.UserId, request.WorkshopId); var workshopToUpdate = await _workshopService.GetById(request.WorkshopId); if (existingRegistration == null && request.IsPaid) { await _registrationService.Create(new Registration { UserId = request.UserId, WorkshopId = request.WorkshopId, IsPaid = request.IsPaid, IsDesired = false, }); workshopToUpdate.CurrentUsersCount++; await _workshopService.Update(workshopToUpdate); } else if (request.IsDesired) { await _registrationService.Create(new Registration { UserId = request.UserId, WorkshopId = request.WorkshopId, IsPaid = false, IsDesired = request.IsDesired, }); } else { existingRegistration.IsPaid = true; existingRegistration.IsDesired = false; await _registrationService.Update(existingRegistration); workshopToUpdate.CurrentUsersCount++; await _workshopService.Update(workshopToUpdate); } return(Ok()); }
public IActionResult EditWorkshop(int id, [FromBody] Workshop incomingModel) { if (incomingModel.Id == id) { workshopService.Update(incomingModel); workshopService.Save(); } return(RedirectToAction("GetAll", "Workshop")); }
public ActionResult Update(int id, WorkshopDto workshopUpdateDto) { var model = service.GetWorkshopById(id); if (model == null) { return(NotFound()); } mapper.Map(workshopUpdateDto, model); service.Update(model); service.Save(); return(NoContent()); }
public IActionResult Edit(WorkshopDto incomingModel) { if (incomingModel.ID > 0) { if (ModelState.IsValid) { var workshopInDb = new Workshop(); workshopInDb = mapper.Map <Workshop>(incomingModel); service.Update(workshopInDb); service.Save(); return(RedirectToAction("List", "Workshops")); } } return(View(incomingModel)); }
public IActionResult UpdateOrder(List <OrderUpdateModel> postModel) { var rows = _IWorkshopService.Where().Result.ToList(); postModel.ForEach(o => { var row = rows.FirstOrDefault(r => r.Id == o.Id); if (row != null) { row.OrderNo = o.OrderNo; _IWorkshopService.Update(row); } }); _uow.SaveChanges(); return(Json("ok")); }
public async Task <IActionResult> Update([FromBody] UpdateWorkshopRequest request) { var workshopToUpdate = await _service.GetById(request.Id); if (workshopToUpdate == null) { return(NotFound()); } workshopToUpdate.Category = request.Category; workshopToUpdate.ChoreographerId = request.ChoreographerId; workshopToUpdate.Style = request.Style; workshopToUpdate.Price = request.Price; workshopToUpdate.Date = DateTimeOffset.Parse(request.Date.ToString()); workshopToUpdate.Time = DateTimeOffset.Parse(request.Time.ToString()); workshopToUpdate.PlaceId = request.PlaceId; workshopToUpdate.MinAge = request.MinAge; workshopToUpdate.MaxUsers = request.MaxUsers; workshopToUpdate.IsClosed = request.IsClosed; workshopToUpdate.PhotoName = request.PhotoName; workshopToUpdate.Photo = request.Photo.Contains("data") ? PreparePhoto(request.Photo) : Convert.FromBase64String(request.Photo); return(Ok(await _service.Update(workshopToUpdate))); }