コード例 #1
0
        public ActionResult Check(CheckCardSerialRequest model)
        {
            ApiResult ap = new ApiResult();

            using (DLSMEntities context = new DLSMEntities())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var result = context.sp_ApiCheckCardSerial(model.WhID, model.SerialNo).ToList();
                        if (result.Count() > 0)
                        {
                            context.SaveChanges();
                            dbContextTransaction.Commit();
                            ap.Code = "1";
                        }
                        else
                        {
                            dbContextTransaction.Rollback();
                            ap.Code = "2";
                        }
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                        ap.Code    = "0";
                        ap.Message = ex.Message;
                    }
                }
            }
            return(Json(ap));
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                CheckCardSerialRequest parm = new CheckCardSerialRequest();
                using (StreamReader sr = new StreamReader(context.Request.InputStream))
                {
                    String data = sr.ReadToEnd();
                    parm    = new JavaScriptSerializer().Deserialize <CheckCardSerialRequest>(data);
                    cardEIN = parm.cardEIN;
                }

                ApiCheckResponse ap = new ApiCheckResponse();
                using (DLSMEntities db = new DLSMEntities())
                {
                    using (var dbContextTransaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            var result = db.sp_ApiCheckCardSerial(Convert.ToInt32(parm.WH_ID), parm.cardEIN, Convert.ToInt32(parm.staffId)).ToList();
                            if (result.Count() > 0)
                            {
                                db.SaveChanges();
                                dbContextTransaction.Commit();
                                ap.resultCode = "1";
                                ap.cardEIN    = parm.cardEIN;
                                ap.message    = "OK";
                            }
                            else
                            {
                                dbContextTransaction.Rollback();
                                ap.cardEIN    = parm.cardEIN;
                                ap.resultCode = "0";
                                ap.message    = "not found";
                            }
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                            ap.cardEIN    = parm.cardEIN;
                            ap.resultCode = "0";
                            ap.message    = ex.InnerException == null ? (ex.Message == null ? "Error: CheckCardSerial catch 2" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace;
                        }
                    }
                }
                string json = new JavaScriptSerializer().Serialize(ap);

                context.Response.ContentType = "text/javascript";
                context.Response.Write(json);
            }
            catch (Exception ex)
            {
                ApiCheckResponse ap = new ApiCheckResponse();
                ap.cardEIN    = cardEIN;
                ap.resultCode = "0";
                ap.message    = ex.InnerException == null ? (ex.Message == null ? "Error: CheckCardSerial catch 1" : ex.Message) : ex.InnerException.Message + " StackTrace:" + ex.StackTrace;


                string json = new JavaScriptSerializer().Serialize(ap);
                context.Response.ContentType = "text/javascript";
                context.Response.Write(json);
            }
        }