Ejemplo n.º 1
0
        public async Task <IActionResult> PutVehicle([FromRoute] int id, [FromBody] Vehicle vehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != vehicle.Id)
            {
                return(BadRequest());
            }

            _context.Entry(vehicle).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <Customer> Create(Customer customer)
        {
            _context.Customers.Add(customer);
            await _context.SaveChangesAsync();

            return(customer);
        }
Ejemplo n.º 3
0
        public async Task <int> InsertAsync(TEntity entity)
        {
            try
            {
                if (entity == null)
                {
                    throw new ArgumentException("entity");
                }
                Entities.Add(entity);
                return(await Context.SaveChangesAsync());
            }
            catch (DbEntityValidationException dbEx)
            {
                var msg = string.Empty;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        msg += string.Format("Property: {0} Error: {1}",
                                             validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine;
                    }
                }

                var fail = new Exception(msg, dbEx);
                throw fail;
            }
        }
        public async Task <ActionResult <Vehicle> > PostVehicle(Vehicle vehicle)
        {
            _context.Vehicles.Add(vehicle);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetVehicles), new { id = vehicle.Id }, vehicle));
        }
        public async Task <VehicleModel> CreateModelAsync(VehicleModel newModel)
        {
            context.VehicleModels.Add(newModel);
            await context.SaveChangesAsync();

            return(newModel);
        }
Ejemplo n.º 6
0
        public async Task <Vehicle> Create(Vehicle vehicle)
        {
            _context.Vehicles.Add(vehicle);
            await _context.SaveChangesAsync();

            return(vehicle);
        }
Ejemplo n.º 7
0
        public async Task <ResultModel <VehicleModel> > Create(VehicleModel model)
        {
            try
            {
                var validationErrors = CheckCreateValidations(model);
                if (validationErrors.Any())
                {
                    return(new ErrorResultModel <VehicleModel>(validationErrors));
                }
                var entity = ToEntity(model);

                await _context.Vehicles.AddAsync(entity);

                var rowsAffected = await _context.SaveChangesAsync();

                if (rowsAffected > 0)
                {
                    model.Id = entity.Id;
                    return(new SuccessResultModel <VehicleModel>(model));
                }
                else
                {
                    return(new ErrorResultModel <VehicleModel>("No se pudo guardar el vehiculo"));
                }
            }
            catch (Exception e)
            {
                return(new ErrorResultModel <VehicleModel>(e.Message));
            }
        }
        public async Task <VehicleMake> CreateMakeAsync(VehicleMake newMake)
        {
            context.VehicleMakes.Add(newMake);
            await context.SaveChangesAsync();

            return(newMake);
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> PutVehicle(string vin, Vehicle vehicle)
        {
            if (vin != vehicle.VIN)
            {
                return(BadRequest());
            }

            _context.Entry(vehicle).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VehicleExists(vin))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("ID,Question,Answer,Type,Creator")] Rule rule)
        {
            var user = await _userManager.GetUserAsync(User);

            rule.Creator = user.UserName;
            rule.State   = State.Pending;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(rule);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RuleExists(rule.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.)
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(rule));
        }
        public async Task <Vehicle> SaveVehicle(Vehicle vehicle)
        {
            await _context.Vehicles.AddAsync(vehicle);

            await _context.SaveChangesAsync();

            return(vehicle);
        }
Ejemplo n.º 12
0
        public async Task <T> CreteAsync(T newItem)
        {
            await context.Set <T>().AddAsync(newItem);

            await context.SaveChangesAsync();

            return(newItem);
        }
        /// <summary>
        /// Instert new vehicle.
        /// </summary>
        /// <param name="vehicleModel">Vehicle model.</param>
        /// <returns>Updates database.</returns>
        public Task InsertVehicleAsync(IVehicleModel vehicleModel)
        {
            vehicleModel.Id   = Guid.NewGuid();
            vehicleModel.Abrv = vehicleModel.Name.Substring(0, 3);
            vehicleContext.VehicleModels.Add(mapper.Map <DAL.Entities.VehicleModel>(vehicleModel));

            return(vehicleContext.SaveChangesAsync());
        }
Ejemplo n.º 14
0
        public async Task <Guid> Create(TEntity entity)
        {
            await authContext.Set <TEntity>().AddAsync(entity);

            await authContext.SaveChangesAsync();

            return(entity.Id);
        }
        public async Task <ItemsInStockModel> AddAsync(ItemsInStockModel model)
        {
            await StockEntities.AddAsync(model);

            await Context.SaveChangesAsync();

            return(model);
        }
 public async Task <int> InsertAsync(TEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentException("entity");
     }
     Entities.Add(entity);
     return(await Context.SaveChangesAsync());
 }
Ejemplo n.º 17
0
        public async Task <ActionResult <Vehicle> > AddVehicle([FromBody] Vehicle vehicle)
        {
            _context.Vehicles.Add(vehicle);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       "GetVehiclebyID",

                       new { id = vehicle.Id }, vehicle
                       ));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Create([Bind("Id,Patente,Marca,Modelo,Puertas,Titular")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicle));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create([Bind("ID,Question,Answer,State,Type,Creator")] Rule rule)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rule);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rule));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Create([Bind("Id,VehicleRegNumber,DateOfRegistration,OwnerNationalIdNumber,MonthlyInsuranceAmount")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicle));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Create([Bind("Id,Brand,Model,Year")] Car car)
        {
            if (ModelState.IsValid)
            {
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("VehicleID,Type,GasAmount,TiresNum")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(vehicle));
        }
Ejemplo n.º 23
0
        public async Task <int> AddModel(VehicleModel model)
        {
            if (db != null)
            {
                db.vehicleModels.Add(model);
                await db.SaveChangesAsync();

                return(model.ID);
            }

            return(0);
        }
Ejemplo n.º 24
0
        public async Task <ActionResult> Create(VehicleModel vehicleModel)
        {
            if (ModelState.IsValid)
            {
                db.VehicleModels.Add(vehicleModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(vehicleModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "ID,Name,Abrv")] VehicleMake vehicleMake)
        {
            if (ModelState.IsValid)
            {
                db.vehicleMakes.Add(vehicleMake);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(vehicleMake));
        }
Ejemplo n.º 26
0
        public async Task <int> AddMake(VehicleMake make)
        {
            if (db != null)
            {
                db.vehicleMakes.Add(make);
                await db.SaveChangesAsync();

                return(make.ID);
            }

            return(0);
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Create([Bind("ID,Model,VType,Brand,Capacity,Description,ReleaseDate")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(User);

                vehicle.ModifyBy = user.UserName;
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicle));
        }
Ejemplo n.º 28
0
        public async Task <bool> InsertMake(VehicleMake make)
        {
            try
            {
                context.VehicleMakes.Add(make);
                await context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 29
0
        public async Task <bool> InsertModel(VehicleModel model)
        {
            try
            {
                context.VehicleModels.Add(model);
                await context.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 30
0
        public async Task <bool> CreateVehicleModel(VehicleModel vehicleModelToInsert)
        {
            try
            {
                _datacontext.VehicleModels.Add(vehicleModelToInsert);
                await _datacontext.SaveChangesAsync();

                return(true);
            }

            catch
            {
                return(false);
            }
        }