Exemplo n.º 1
0
        public async Task <IHttpActionResult> Postmst_operator(mst_operator mst_operator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.mst_operator.Add(mst_operator);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (mst_operatorExists(mst_operator.OperatorID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = mst_operator.OperatorID }, mst_operator));
        }
Exemplo n.º 2
0
        public async Task UpdateAsync(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_UpdateOperator] @operatorCode, @operatorName", param);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> Putmst_operator(string id, mst_operator mst_operator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mst_operator.OperatorID)
            {
                return(BadRequest());
            }

            db.Entry(mst_operator).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!mst_operatorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Getmst_operator(string id)
        {
            mst_operator mst_operator = await db.mst_operator.FindAsync(id);

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

            return(Ok(mst_operator));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> Deletemst_operator(string id)
        {
            mst_operator mst_operator = await db.mst_operator.FindAsync(id);

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

            db.mst_operator.Remove(mst_operator);
            await db.SaveChangesAsync();

            return(Ok(mst_operator));
        }
Exemplo n.º 6
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());
 }
Exemplo n.º 7
0
        private void txtOperatorID_Validating(object sender, CancelEventArgs e)
        {
            string operatorCode = txtOperatorID.Text;

            if (!string.IsNullOrEmpty(operatorCode))
            {
                _operator = _oqcService.GetOperatorByCode(operatorCode);
                if (_operator == null)
                {
                    Ultils.EditTextErrorMessage(txtOperatorID, "Opeator code không tồn tại trong hệ thống!");
                }
                else
                {
                    txtLineID.Focus();
                }
            }
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
0
        private void txtOperatorID_Validating(object sender, CancelEventArgs e)
        {
            string operatorCode = txtOperatorID.Text;

            if (string.IsNullOrEmpty(operatorCode))
            {
                Ultils.TextControlNotNull(txtOperatorID, "Operator");
                txtOperatorID.SelectAll();
            }
            else
            {
                var operators = _oqcService.GetOperatorByCode(operatorCode);
                if (operators == null)
                {
                    Ultils.EditTextErrorMessage(txtOperatorID, "Opeator code không tồn tại trong hệ thống!");
                }
                else
                {
                    _operator = operators;
                }
            }
        }