Esempio n. 1
0
        public IHttpActionResult Create(CreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            UserInt user    = UserIntFactory.CreateFromIdentity(_uow, User);
            Vehicle vehicle = model.GetVehicle(user);

            _uow.GetRepository <IVehicleRepository>().Add(vehicle);
            _uow.Commit();
            _uow.RefreshAllEntities();

            Blog blog = new Blog
            {
                Vehicle   = vehicle,
                VehicleId = vehicle.VehicleId,
                AuthorId  = user.Id,
                Name      = vehicle.Make + " " + vehicle.Model // TODO :: ugly
            };

            _uow.GetRepository <IBlogRepository>().Add(blog);
            _uow.Commit();

            if (_userManager.IsInRole(User.Identity.GetUserId <int>(), "CarOwner") == false)
            {
                _userManager.AddToRole(User.Identity.GetUserId <int>(), "CarOwner");
            }

            return(Ok(model));
        }