Beispiel #1
0
 public async Task<ActionResult> Edit(mst_operator operatorModel)
 {
     if (ModelState.IsValid)
     {
         try
         {
             await operatorService.UpdateAsync(operatorModel);
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("OperatorName", ex.Message);
         }
         return RedirectToAction("Index");
     }
     return View();
 }
Beispiel #2
0
        public async Task<ActionResult> Create(OperatorAddModel operatorModel)
        {
            if (ModelState.IsValid)
            {
                mst_operator opera = new mst_operator
                {
                    OperatorID = operatorModel.OperatorID,
                    OperatorName = operatorModel.OperatorName,
                };

                try
                {
                    await operatorService.InsertAsync(opera);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("OperatorName", ex.Message);
                }
                return RedirectToAction("Index");
            }
            return PartialView();
        }
Beispiel #3
0
        public async Task InsertAsync(mst_operator opera)
        {
            object[] param =
            {
                new SqlParameter() { ParameterName = "@operatorCode", Value = opera.OperatorID, SqlDbType = SqlDbType.Char},
                new SqlParameter() { ParameterName = "@operatorName", Value = opera.OperatorName, SqlDbType = SqlDbType.NVarChar},
                new SqlParameter("@Out_Parameter", SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                }
            };

            try
            {
                _context.Database.ExecuteSqlCommand("EXEC [sp_InsertOperator] @operatorCode, @operatorName", param);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

        }