Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        public IActionResult EditWorkshop(int id, [FromBody] Workshop incomingModel)
        {
            if (incomingModel.Id == id)
            {
                workshopService.Update(incomingModel);
                workshopService.Save();
            }



            return(RedirectToAction("GetAll", "Workshop"));
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
 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));
 }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        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)));
        }