public async Task <IActionResult> AddNewMobile(MobilesModels mobilesModels) { if (ModelState.IsValid) { int id = await _mobileRepository.AddNewMobile(mobilesModels); if (id > 0) { return(RedirectToAction(nameof(AddNewMobile), new { isSuccess = true, mobileId = id })); } } return(View()); }
public async Task <int> AddNewMobile(MobilesModels mobilesModels) { var newMobile = new Mobile() { MobileName = mobilesModels.MobileName, CreateOn = DateTime.UtcNow, Description = mobilesModels.Description, MobileVersion = mobilesModels.MobileVersion, Language = mobilesModels.Language, Price = mobilesModels.Price.HasValue ? mobilesModels.Price.Value : 0, UpdateOn = DateTime.UtcNow }; await _context.Mobiles.AddAsync(newMobile); await _context.SaveChangesAsync(); return(newMobile.Id); }
public async Task <MobilesModels> GetMobilesById(int id) { var mobile = await _context.Mobiles.FindAsync(id); if (mobile != null) { var mobileDetails = new MobilesModels() { MobileName = mobile.MobileName, Id = mobile.Id, Color = mobile.Color, Description = mobile.Description, MobileVersion = mobile.MobileVersion, Language = mobile.Language, Price = mobile.Price }; return(mobileDetails); } else { return(null); } }