Пример #1
0
 public async Task <IActionResult> UpdateAsync([FromBody] UpdatePerformanceModel model)
 {
     _logger.LogInformation($"Update {model.Id} performance");
     if (ModelState.IsValid)
     {
         if (await _service.UpdateAsync(_mapper.Map <PerformanceDTO>(model)))
         {
             return(Ok());
         }
         return(BadRequest());
     }
     return(BadRequest(ModelState));
 }
Пример #2
0
        public Performance Map(UpdatePerformanceModel model, Guid performanceId)
        {
            var entity = Process.GetPerformance(performanceId);

            entity.StartDateTime = new DateTime(model.Date.Year, model.Date.Month, model.Date.Day,
                                                model.StartTime.Hour, model.StartTime.Minute,
                                                model.StartTime.Second, model.StartTime.Millisecond);
            entity.EndDateTime = new DateTime(model.EndTime.Year, model.EndTime.Month, model.EndTime.Day,
                                              model.EndTime.Hour, model.EndTime.Minute,
                                              model.EndTime.Second, model.EndTime.Millisecond);
            entity.City      = model.City;
            entity.Info      = model.Info;
            entity.Price     = model.Price;
            entity.VenueName = model.VenueName;
            entity.VenueUri  = GetUri(model.VenueUrl);

            return(entity);
        }
Пример #3
0
        public void When_UpdatePerformance_is_mapped_to_a_Performance_and_the_VenueUrl_is_null_then_all_fields_are_mapped_correctly_and_VenueUri_in_the_result_is_null()
        {
            var startDateTime = DateTime.Now.AddDays(37);
            var endDateTime   = startDateTime.AddHours(4);

            var entity = PerformanceCreator.CreateSingleFuture();

            PerformanceProcess
            .Expect(process =>
                    process.GetPerformance(entity.Id))
            .Return(entity)
            .Repeat.Once();
            PerformanceProcess.Replay();

            var updateModel = new UpdatePerformanceModel
            {
                Id        = entity.Id,
                Date      = startDateTime.Date,
                StartTime = startDateTime,
                EndTime   = endDateTime,
                City      = "City",
                Info      = "Info",
                Price     = DateTime.UtcNow.Ticks,
                VenueUrl  = null,
            };

            var result = Mapper.Map(updateModel, entity.Id);

            Assert.AreEqual(entity.Id, result.Id, "Id not correct");
            Assert.AreEqual(updateModel.Date.ToString("ddMMyyyy", CultureInfo.InvariantCulture), result.StartDateTime.ToString("ddMMyyyy", CultureInfo.InvariantCulture), "StartDateTime not correct");
            Assert.AreEqual(updateModel.StartTime.ToString("HHmm", CultureInfo.InvariantCulture), result.StartDateTime.ToString("HHmm", CultureInfo.InvariantCulture), "StartDateTime not correct");
            Assert.AreEqual(updateModel.EndTime.ToString("HHmm", CultureInfo.InvariantCulture), result.EndDateTime.ToString("HHmm", CultureInfo.InvariantCulture), "EndDateTime not correct");
            Assert.AreEqual(updateModel.City, result.City, "City not correct");
            Assert.AreEqual(updateModel.Info, result.Info, "Info not correct");
            Assert.AreEqual(updateModel.Price, result.Price, "Proce not correct");
            Assert.AreEqual(updateModel.VenueName, result.VenueName, "VenueName not correct");
            Assert.AreEqual(null, result.VenueUri, "VenueUri not correct");

            PerformanceProcess.VerifyAllExpectations();
        }
Пример #4
0
        public async Task <ActionResult> Edit(Guid id, UpdatePerformanceModel model)
        {
            try
            {
                return(await CatalogsConsumerHelper.ExecuteWithCatalogScopeAsync(
                           container =>
                {
                    var mapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IPerformanceMapper>(container);
                    var entity = mapper.Map(model, id);

                    var process = CatalogsConsumerHelper.ResolveCatalogsConsumer <IPerformanceProcess>(container);
                    process.UpdatePerformance(entity);

                    return RedirectToAction("Index");
                }));
            }
            catch
            {
                ModelState.AddModelError("", ExceptionMessages.GenericExceptionMessage);
                return(View(model));
            }
        }