Exemplo n.º 1
0
 public void SaveChanges(IVehicleMake vehicleMake)
 {
     if (vehicleMake.Id == 0)
     {
         context.Add(mapper.Map <VehicleMake>(vehicleMake));
         context.SaveChanges();
     }
     else
     {
         var vehicle = context.VehicleMakers.Attach(mapper.Map <VehicleMake>(vehicleMake));
         vehicle.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Label")] Drive drive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(drive);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(drive));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,CylindersId,Displacement,DriveId,FuelCost,FuelTypeId,MakeId,Model,TransmissionId,CityMilage,HighwayMilage,VehicleClassId,YearId")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CylindersId"] = new SelectList(_context.Cylinders, "Id", "Id", vehicle.CylindersId);
            return(View(vehicle));
        }
Exemplo n.º 4
0
        private async Task <long> SaveUserFile(long?fileId, IFormFile formFile, string name)
        {
            UserFileItem userFile = null;

            if (fileId != null)
            {
                userFile = _context.Files.FirstOrDefault(f => f.Id == fileId);
                string spath = Path.Combine(_hostingEnvironment.WebRootPath, "upload", userFile.ServerPath);
                System.IO.File.Move(spath, spath + ".deleted");
            }
            if (userFile == null)
            {
                userFile = new UserFileItem();
            }
            string serverFileName = Guid.NewGuid().ToString() + ".ufile";
            string serverPath     = Path.Combine(_hostingEnvironment.WebRootPath, "upload", serverFileName);

            FileStream fileToWrite = new FileStream(serverPath, FileMode.Create, FileAccess.Write);
            await formFile.CopyToAsync(fileToWrite);

            fileToWrite.Close();

            userFile.TownId  = GroupItem.TownId;
            userFile.GroupId = GroupItem.Id;

            userFile.Visibility  = VisibilityType.CurrentGroup;
            userFile.FileName    = Path.GetFileName(formFile?.FileName);
            userFile.ContentType = formFile?.ContentType;
            userFile.ServerPath  = serverFileName;
            userFile.ClientPath  = formFile?.FileName;
            userFile.Size        = formFile?.Length ?? 0;
            userFile.Name        = name;
            userFile.Type        = Path.GetExtension(formFile?.FileName);


            if (fileId != null)
            {
                _context.Attach(userFile).State = EntityState.Modified;
            }
            else
            {
                _context.Add(userFile);
            }
            await _context.SaveChangesAsync();

            return(userFile.Id);
        }