public ActionResult Create()
        {
            var _model = new AndroidViewModel();

            _model.JobsList = new SelectList(this._jobService.GetAll(), "Id", "Name");
            return(View(_model));
        }
 public ActionResult Create(AndroidViewModel android, HttpPostedFileBase image = null)
 {
     if (ModelState.IsValid)
     {
         var _androidDto = new AndroidDto {
             Name   = android.Name,
             Skills = android.Skills,
             JobId  = android.JobId
         };
         if (image != null)
         {
             _androidDto.ImageMimeType   = image.ContentType;
             _androidDto.AvatarImageData = new byte[image.ContentLength];
             image.InputStream.Read(_androidDto.AvatarImageData, 0, image.ContentLength);
         }
         try {
             this._androidService.Create(_androidDto);
             return(RedirectToAction("Index", "Android"));
         } catch (ValidationException ex) {
             ModelState.AddModelError(ex.Property, ex.Message);
         }
     }
     else
     {
         var _duplicatedModelState = ModelState.Values.SingleOrDefault(ms => ms.Errors.Count > 1 && ms.Errors[0].ErrorMessage == ms.Errors[1].ErrorMessage);
         if (_duplicatedModelState != null)
         {
             _duplicatedModelState.Errors.Remove(_duplicatedModelState.Errors[1]);
         }
         android.JobsList = new SelectList(this._jobService.GetAll(), "Id", "Name");
     }
     return(View(android));
 }
示例#3
0
        public async Task <IActionResult> Assign(int id, [Bind("Android")] AndroidViewModel androidViewModel)
        {
            if (androidViewModel.Android.CurrentJobId != null)
            {
                var android = await _context.Android.SingleOrDefaultAsync(m => m.Id == id);

                if (android == null)
                {
                    return(NotFound());
                }

                try
                {
                    android.CurrentJobId = androidViewModel.Android.CurrentJobId;
                    android.Reliability--;

                    _context.Update(android);
                    await _context.SaveChangesAsync();
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!AndroidExists(android.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
示例#4
0
        public async Task <IActionResult> Assign(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var android = await _context.Android.SingleOrDefaultAsync(m => m.Id == id);

            if (android == null)
            {
                return(NotFound());
            }

            var activeJobs = await _context.Job
                             .Select(a => new SelectListItem()
            {
                Value = a.Id.ToString(),
                Text  = a.Name
            }).ToListAsync();

            AndroidViewModel androidViewModel = new AndroidViewModel(android, activeJobs);

            return(View(androidViewModel));
        }
示例#5
0
        public async Task <IActionResult> Edit(AndroidViewModel androidView)
        {
            if (ModelState.IsValid)
            {
                Android oldAndroid = await db.Androids.FirstOrDefaultAsync(p => p.Id == androidView.Id);

                Android android = (Android)androidView;
                if (android.Name != null)
                {
                    oldAndroid.Name = android.Name;
                }
                if (android.Skills != null)
                {
                    oldAndroid.Skills = android.Skills;
                }
                if (android.Avatar != null)
                {
                    oldAndroid.Avatar = android.Avatar;
                }
                db.Androids.Update(oldAndroid);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(androidView));
        }
示例#6
0
        public async Task <IActionResult> Create(AndroidViewModel androidView)
        {
            if (ModelState.IsValid)
            {
                Android android = (Android)androidView;
                android.Reability = 10;
                android.Status    = 1;
                db.Androids.Add(android);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(androidView));
        }
        public ActionResult Edit(int androidId)
        {
            var _androidDto = this._androidService.Get(androidId);
            var _adroid     = new AndroidViewModel {
                Id              = _androidDto.Id,
                Name            = _androidDto.Name,
                Skills          = _androidDto.Skills,
                JobId           = _androidDto.JobId,
                IsOk            = _androidDto.IsOk,
                JobsList        = new SelectList(this._jobService.GetAll(), "Id", "Name"),
                Reliability     = _androidDto.Reliability,
                AvatarImageData = _androidDto.AvatarImageData,
                ImageMimeType   = _androidDto.ImageMimeType
            };

            return(View(_adroid));
        }
 public ActionResult Edit(AndroidViewModel android, HttpPostedFileBase image = null)
 {
     if (ModelState.IsValid)
     {
         var _androidDto = new AndroidDto {
             Id          = android.Id,
             Name        = android.Name,
             Skills      = android.Skills,
             JobId       = android.JobId,
             IsOk        = android.IsOk,
             Reliability = android.Reliability,
         };
         if (image != null)
         {
             _androidDto.ImageMimeType   = image.ContentType;
             _androidDto.AvatarImageData = new byte[image.ContentLength];
             image.InputStream.Read(_androidDto.AvatarImageData, 0, image.ContentLength);
         }
         else if (!android.ImageDisabled)
         {
             var _image = this.GetImage(android.Id);
             _androidDto.ImageMimeType   = _image?.ContentType;
             _androidDto.AvatarImageData = _image?.FileContents;
         }
         if (!_androidDto.IsOk)
         {
             _androidDto.JobId = this._androidService.Get(_androidDto.Id).JobId;
         }
         try {
             this._androidService.Update(_androidDto);
             return(RedirectToAction("Index", "Android"));
         } catch (ValidationException ex) {
             ModelState.AddModelError(ex.Property, ex.Message);
         }
     }
     else
     {
         var _duplicatedModelState = ModelState.Values.SingleOrDefault(ms => ms.Errors.Count > 1 && ms.Errors[0].ErrorMessage == ms.Errors[1].ErrorMessage);
         if (_duplicatedModelState != null)
         {
             _duplicatedModelState.Errors.Remove(_duplicatedModelState.Errors[1]);
         }
     }
     return(View(android));
 }