Esempio n. 1
0
 public void Delete(AscmContainerSpec ascmContainerSpec)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmContainerSpec>(ascmContainerSpec);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmContainerSpec)", ex);
         throw ex;
     }
 }
Esempio n. 2
0
 public void Update(AscmContainerSpec ascmContainerSpec)
 {
     try
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmContainerSpec>(ascmContainerSpec);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmContainerSpec)", ex);
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Save AscmContainerSpec)", ex);
         throw ex;
     }
 }
        public ContentResult ContainerSpecSave(AscmContainerSpec ascmContainerSpec_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                string userName = string.Empty;
                if (User.Identity.IsAuthenticated)
                    userName = User.Identity.Name;
                if (ascmContainerSpec_Model.spec == null || ascmContainerSpec_Model.spec.Trim() == "")
                    throw new Exception("容器规格不能为空!");

                AscmContainerSpec ascmContainerSpec = null;
                if (id.HasValue)
                {
                    ascmContainerSpec = AscmContainerSpecService.GetInstance().Get(id.Value);
                    if (ascmContainerSpec == null)
                        throw new Exception("找不到容器规格");
                }
                else
                {
                    ascmContainerSpec = new AscmContainerSpec();
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmContainerSpec");
                    ascmContainerSpec.id = ++maxId;
                    ascmContainerSpec.createUser = userName;
                    ascmContainerSpec.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                }
                ascmContainerSpec.spec = ascmContainerSpec_Model.spec.Trim();

                object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmContainerSpec where id<>" + ascmContainerSpec.id + " and spec='" + ascmContainerSpec.spec + "'");
                if (object1 == null)
                    throw new Exception("查询异常!");
                int iCount = 0;
                if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                    throw new Exception("已经存在此容器规格【" + ascmContainerSpec.spec + "】");

                ascmContainerSpec.modifyUser = userName;
                ascmContainerSpec.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                if (!string.IsNullOrEmpty(ascmContainerSpec_Model.description))
                    ascmContainerSpec.description = ascmContainerSpec_Model.description.Trim();

                if (id.HasValue)
                    AscmContainerSpecService.GetInstance().Update(ascmContainerSpec);
                else
                    AscmContainerSpecService.GetInstance().Save(ascmContainerSpec);

                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
                jsonObjectResult.id = ascmContainerSpec.id.ToString();
                jsonObjectResult.entity = ascmContainerSpec;
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }
            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }