Ejemplo n.º 1
0
        public async Task <PlanModel> UpdatePlan(Guid planGuid, UpdatePlanModel model)
        {
            var entity = await _planData.UpdatePlan(planGuid, model).ConfigureAwait(false);

            var mappedModel = _mapper.Map <PlanModel>(entity);

            return(mappedModel);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> UpdatePlan([FromUri] Guid planGuid, [FromBody] UpdatePlanModel model)
        {
            try
            {
                var result = await _planOperations.UpdatePlan(planGuid, model).ConfigureAwait(false);

                return(Ok(result));
            }
            catch (EntityNotFoundException)
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 3
0
        public async Task UpdatePlan_ShouldReturnBadRequestIfTheEntityDoesNotExist()
        {
            var planOperations = new Mock <IPlanOperations>();

            var guid  = Guid.NewGuid();
            var model = new UpdatePlanModel();

            planOperations.Setup(o => o.UpdatePlan(guid, model)).Throws <EntityNotFoundException>();

            var controller = new PlanController(planOperations.Object);

            var result = await controller.UpdatePlan(guid, model).ConfigureAwait(false);

            Assert.AreEqual(typeof(BadRequestResult), result.GetType());
        }
Ejemplo n.º 4
0
        public async Task<Plan> UpdatePlan(Guid planGuid, UpdatePlanModel model)
        {
            using (var connection = _connectionHelper.GetConnection())
            {
                var result = await connection.ExecuteAsync(
                    "UPDATE [PLAN] SET [Name] = @Name, [Description] = @Description, [Enabled] = @Enabled, [ModificationTime] = @ModificationTime WHERE [Guid] = @Guid",
                    new {Guid = planGuid, model.Name, model.Description, model.Enabled, ModificationTime = DateTime.Now}
                ).ConfigureAwait(false);

                if (result == 0)
                    throw new EntityNotFoundException($"No plan exists for the guid: {planGuid}");

                return await connection
                    .QuerySingleOrDefaultAsync<Plan>("SELECT * FROM [PLAN] WHERE [Guid] = @Guid", new {Guid = planGuid})
                    .ConfigureAwait(false);
                ;
            }
        }
Ejemplo n.º 5
0
        public ActionResult UpdatePlan(UpdatePlanModel model)
        {
            var plan = getPlan(model.planName, model.username);

            if (plan != null)
            {
                //var allDates = model.Date;
                //allDates.ForEach(x => x.ToString());//turn it into json object instead
                //var allDatesString = String.Join(",", allDates);
                //plan.AllDates = allDatesString;
                plan.StartTime = model.StartTime.ToString();
                plan.EndTime   = model.EndTime.ToString();
                plan.City      = model.City;
                plan.Price     = model.Price;

                //var allCusines = model.Cuisine;
            }

            return(View());
        }
Ejemplo n.º 6
0
        public async Task UpdatePlan_ShouldReturnTheUpdatedPlan()
        {
            var planOperations = new Mock <IPlanOperations>();

            var expected = new PlanModel();
            var model    = new UpdatePlanModel();
            var guid     = Guid.NewGuid();

            planOperations.Setup(o => o.UpdatePlan(guid, model)).ReturnsAsync(expected);
            ;

            var controller = new PlanController(planOperations.Object);

            var result =
                await controller.UpdatePlan(guid, model).ConfigureAwait(false) as OkNegotiatedContentResult <PlanModel>;

            if (result == null)
            {
                Assert.Fail();
            }

            Assert.AreEqual(expected, result.Content);
        }