private void SaveServiceLink(HttpContext context) { context.Response.ContentType = "text/plain"; try { string scId = context.Request.Form["hServiceLinkId"].Trim(); string sServiceItemId = context.Request.Form["ServiceItemId"].Trim(); string sNamed = context.Request.Form["txtNamed_ServiceLink"].Trim(); string sPictureId = context.Request.Form["hPictureId_ServiceLink"].Trim(); string sSort = context.Request.Form["Sort"].Trim(); if (string.IsNullOrWhiteSpace(sNamed)) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}"); return; } Guid serviceItemId = Guid.Empty; Guid.TryParse(sServiceItemId, out serviceItemId); Guid pictureId = Guid.Empty; Guid.TryParse(sPictureId, out pictureId); int sort = 0; if (!string.IsNullOrWhiteSpace(sSort)) { int.TryParse(sSort, out sort); } string sUrl = context.Request.Form["txtUrl_ServiceLink"].Trim(); Guid gId = Guid.Empty; if (!string.IsNullOrWhiteSpace(scId)) { Guid.TryParse(scId, out gId); } ServiceLinkInfo model = new ServiceLinkInfo(); model.Id = gId; model.LastUpdatedDate = DateTime.Now; model.ServiceItemId = serviceItemId; model.Named = sNamed; model.PictureId = pictureId; model.Url = sUrl; model.Sort = sort; ServiceLink bll = new ServiceLink(); ServiceItem siBll = new ServiceItem(); var siModel = siBll.GetModel(serviceItemId); if (siModel == null) { context.Response.Write("{\"success\": false,\"message\": \"服务分类【" + serviceItemId + "】" + MessageContent.Submit_Data_NotExists + "\"}"); return; } int effect = -1; using (TransactionScope scope = new TransactionScope()) { if (!gId.Equals(Guid.Empty)) { effect = bll.Update(model); if ((!siModel.HasContent) && effect > 0) { siModel.HasLink = true; siBll.Update(siModel); } } else { effect = bll.Insert(model); if ((!siModel.HasLink) && effect > 0) { siModel.HasLink = true; siBll.Update(siModel); } } scope.Complete(); } if (effect < 1) { context.Response.Write("{\"success\": false,\"message\": \"操作失败,请正确输入\"}"); return; } context.Response.Write("{\"success\": true,\"message\": \"操作成功\"}"); } catch (Exception ex) { context.Response.Write("{\"success\": false,\"message\": \"异常:" + ex.Message + "\"}"); } }