public async Task <IActionResult> PutUser([FromRoute] Guid id, [FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Name,MobileNumber")] Profile profile) { if (ModelState.IsValid) { profile.Id = Guid.NewGuid(); _context.Add(profile); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(profile)); }
public async Task <IActionResult> UploadForm() { String folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\websync"; String fileName = "Excel_" + DateTime.Now.ToLongDateString() + ".xlsx"; if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } String fullPath = folder + "\\" + fileName; FormValueProvider formModel; using (var stream = System.IO.File.Create(fullPath)) { formModel = await Request.StreamFile(stream); } var viewModel = new MyViewModel(); var bindingSuccessful = await TryUpdateModelAsync(viewModel, prefix : "", valueProvider : formModel); if (!bindingSuccessful) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } } IList <Lead> leads = ExcelFileHandler.LoadExcelData(fullPath, _context.LeadSources.ToList()); if (leads == null) { return(BadRequest("Marked with * are must, " + "please update the missed fields and upload again")); } else { _context.Leads.AddRange(leads.ToArray()); await _context.SaveChangesAsync(); return(View(nameof(Index), leads)); } }