public HttpResponseMessage Add() { var deserializer = new JavaScriptSerializer(); T_Planing_Action_AppliedCoatingMobileBAL mobileBal = new T_Planing_Action_AppliedCoatingMobileBAL(); ResposeType response = new ResposeType(); HttpResponseMessage mapMessage = null; T_Planing_Action_AppliedCoatingMobileDTO dto = null; List <T_Planing_Action_AppliedCoating_InformationMobileDTO> coatingInfomationList = null; try { var context = HttpContext.Current; context.Response.ContentType = "multipart/form-data"; dto = ConvertX.GetReqeustFormExactly <T_Planing_Action_AppliedCoatingMobileDTO>(); //dto.ID = context.Request.Form["ID"]; //dto.PID = context.Request.Form["PID"]; string UserID = context.Request.Form["UserID"]; dto.CreateBy = UserID; dto.UpdateBy = UserID; //fileList = deserializer.Deserialize<List<T_Planing_File>>(context.Request.Form["surfaceList"]); coatingInfomationList = deserializer.Deserialize <List <T_Planing_Action_AppliedCoating_InformationMobileDTO> >(context.Request.Form["coatingInfomationList"]); if (coatingInfomationList != null) { foreach (T_Planing_Action_AppliedCoating_InformationMobileDTO coatingDto in coatingInfomationList) { coatingDto.InfoType = "1"; coatingDto.InfoDate = string.Format("{0}/{1}/{2}", DateTime.Now.Month.ToString("##00"), DateTime.Now.Day.ToString("##00"), DateTime.Now.Year.ToString()); } } dto.CoatingInfoList = coatingInfomationList; dto.UploadFileList = deserializer.Deserialize <List <T_PlaningFileMobileDTO> >(context.Request.Form["fileList"]); logger.debug("PlanActionAppliedCoatingController Add dto:" + dto.ToString()); if (dto.CoatingInfoList != null && dto.CoatingInfoList.Count > 0) { foreach (T_Planing_Action_AppliedCoating_InformationMobileDTO coating in dto.CoatingInfoList) { logger.debug("PlanActionAppliedCoatingController Add coating:" + coating.ToString()); } } if (dto.UploadFileList != null && dto.UploadFileList.Count > 0) { foreach (T_PlaningFileMobileDTO file in dto.UploadFileList) { file.DesPath = context.Server.MapPath(planPath) + @"\" + file.PID + @"\" + file.UploadType; file.FullPath = file.DesPath + @"\" + file.FileName; logger.debug("PlanActionAfterAppliedCoating Add file:" + file.ToString()); } } response.statusCode = mobileBal.AddFromMobile(dto); if (response.statusCode) { response.statusText = "Success"; try { // For new upload if (dto.UploadFileList != null && dto.UploadFileList.Count > 0) { foreach (T_PlaningFileMobileDTO f in dto.UploadFileList) { if (DTO.PTT.Util.FileMng.HaveDirectory(f.DesPath)) { logger.debug("Save file to :" + f.FullPath); Utility.saveBase64File(f.FullPath, f.Base64File); } } } if (dto.DeleteFileNames != null && dto.DeleteFileNames.Length > 0) { foreach (var fileName in dto.DeleteFileNames.Split(',')) { if (fileName != "") { var realDesFile = context.Server.MapPath(planPath) + @"\" + dto.PID + @"\" + fileName; DTO.PTT.Util.FileMng.DeleteFile(realDesFile); } } } }catch (Exception e) { response.statusText = "Success but upload error:" + e.ToString(); } } } catch (Exception ex) { logger.error("Add error:" + ex.ToString()); response.statusText = ex.ToString(); } mapMessage = Request.CreateResponse(HttpStatusCode.OK, response); return(mapMessage); }
public bool AddFromMobile(object data) { List <SqlParameter> parameterList = new List <SqlParameter>(); string procName = "sp_T_Planing_Action_AppliedCoating_Insert_Mobile"; string TPID = ""; SqlConnection conn = null; SqlTransaction transaction = null; isCan = true; try { if (data != null) { conn = OpenConnection(); transaction = conn.BeginTransaction(); T_Planing_Action_AppliedCoatingMobileDTO obj = (T_Planing_Action_AppliedCoatingMobileDTO)data; command = new SqlCommand(procName, conn, transaction); command.CommandType = CommandType.StoredProcedure; parameterList.AddRange(GetParametersExactly(procName, obj, transaction).ToArray()); command.Parameters.AddRange(parameterList.ToArray()); command.ExecuteNonQuery(); TPID = obj.TPID; procName = "sp_T_Planing_Action_AppliedCoating_SurfaceProfile_Insert_Mobile"; if (obj.UploadFileList != null && obj.UploadFileList.Count > 0) { foreach (T_PlaningFileMobileDTO file in obj.UploadFileList) { file.TPID = TPID; command = new SqlCommand(procName, conn, transaction); command.CommandType = CommandType.StoredProcedure; if (file != null) { parameterList = new List <SqlParameter>(); parameterList.AddRange(GetParametersExactly(procName, file, transaction).ToArray()); command.Parameters.AddRange(parameterList.ToArray()); } command.ExecuteNonQuery(); } } procName = "sp_T_Planing_Action_AppliedCoating_Information_Insert_Mobile"; if (obj.CoatingInfoList != null && obj.CoatingInfoList.Count > 0) { foreach (T_Planing_Action_AppliedCoating_InformationMobileDTO dto in obj.CoatingInfoList) { dto.TPID = TPID; command = new SqlCommand(procName, conn, transaction); command.CommandType = CommandType.StoredProcedure; if (dto != null) { parameterList = new List <SqlParameter>(); parameterList.AddRange(GetParametersExactly(procName, dto, transaction).ToArray()); command.Parameters.AddRange(parameterList.ToArray()); } command.ExecuteNonQuery(); } } transaction.Commit(); } } catch (Exception ex) { isCan = false; if (transaction != null) { transaction.Rollback(); } throw new Exception(ex.Message); } finally { CloseConnection(); } return(isCan); }