public async Task <ActionResult> Create(ModelPCB modelView) { if (ModelState.IsValid) { ModelPCB model = new ModelPCB { ModelID = Guid.NewGuid().ToString(), ModelName = modelView.ModelName, CreatedBy = User.Identity.Name, DateCreated = DateTime.Now, Quantity = modelView.Quantity, SerialNo = modelView.SerialNo, CustomerName = modelView.CustomerName, }; try { await modelService.InsertAsync(model); } catch (Exception ex) { ModelState.AddModelError("ModelName", ex.Message); } return(RedirectToAction("Index")); } return(PartialView()); }
public async Task InsertAsync(ModelPCB model) { object[] param = { new SqlParameter() { ParameterName = "@ModelID", Value = model.ModelID, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@ModelName", Value = model.ModelName, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@CreatedBy", Value = model.CreatedBy, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@DateCreated", Value = model.DateCreated, SqlDbType = SqlDbType.DateTime }, new SqlParameter() { ParameterName = "@Quantity", Value = model.Quantity, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@SerialNo", Value = model.SerialNo, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@CustomerName", Value = model.CustomerName, SqlDbType = SqlDbType.VarChar }, new SqlParameter("@Out_Parameter", SqlDbType.Int) { Direction = ParameterDirection.Output } }; try { _context.Database.ExecuteSqlCommand("EXEC [sp_InsertModel] @ModelID, @ModelName, @CreatedBy, @DateCreated, @Quantity, @SerialNo, @CustomerName", param); await _context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult> Edit(ModelPCB modelView) { if (ModelState.IsValid) { try { modelView.CreatedBy = User.Identity.Name; modelView.DateCreated = DateTime.Now; await modelService.UpdateAsync(modelView); } catch (Exception ex) { ModelState.AddModelError("ModelName", ex.Message); } return(RedirectToAction("Index")); } return(View()); }