public HttpResponseMessage Add() { ResposeType response = new ResposeType(); HttpResponseMessage mapMessage = null; try { var context = HttpContext.Current; T_PlaningMobileDTO planingDTO = GetRequestToObjectMobile(context); T_PlaningCoatingRepairMobileDTO planingCoatingRepairDTO = ConvertX.GetReqeustForm <T_PlaningCoatingRepairMobileDTO>(); string UserID = context.Request.Form["UserID"]; if (ObjUtil.isEmpty(UserID)) { throw new Exception("UserID is require"); } planingDTO.CreateBy = UserID; planingDTO.UpdateBy = UserID; planingCoatingRepairDTO.CreateBy = UserID; planingCoatingRepairDTO.UpdateBy = UserID; T_PlaningMobileBAL mobileBal = new T_PlaningMobileBAL(); logger.debug("PlanController Add planingDTO:" + planingDTO.ToString()); logger.debug("PlanController Add planingCoatingRepairDTO:" + planingCoatingRepairDTO.ToString()); string TPID = mobileBal.AddFromMobile(planingDTO, planingCoatingRepairDTO, null, null, null); response.statusCode = true; response.statusText = "TPID"; response.data = TPID; } catch (Exception ex) { logger.error("Add error:" + ex.ToString()); response.statusText = ex.ToString(); } mapMessage = Request.CreateResponse(HttpStatusCode.OK, response); return(mapMessage); }
T_PlaningMobileDTO GetRequestToObjectMobile(HttpContext context) { HttpPostedFile postFile = null; T_PlaningMobileDTO planingDTO = ConvertX.GetReqeustForm <T_PlaningMobileDTO>(); if (context.Request.Files.Count > 0) { foreach (string fileUploadName in context.Request.Files) { if (fileUploadName.ToLower().IndexOf("defect") > -1) { postFile = context.Request.Files[fileUploadName]; var fileName = System.IO.Path.GetFileName(postFile.FileName); var ext = System.IO.Path.GetExtension(postFile.FileName); // fileName = string.Format("{0}.{1}", Guid.NewGuid(), ext); logger.debug("Save file as :" + context.Server.MapPath("~/Files/" + fileName)); postFile.SaveAs(context.Server.MapPath("~/Files/" + fileName)); if (fileUploadName.ToLower().Equals("defect-0")) { planingDTO.FileName1 = fileName; } if (fileUploadName.ToLower().Equals("defect-1")) { planingDTO.FileName2 = fileName; } if (fileUploadName.ToLower().Equals("defect-2")) { planingDTO.FileName3 = fileName; } if (fileUploadName.ToLower().Equals("defect-3")) { planingDTO.FileName4 = fileName; } } } } return(planingDTO); }
public string AddFromMobile(object planObj , object coatingRepairObj , List <object> coatingDefectObj , List <object> pipeDefectObj , List <object> environmentObj) { string TPID = ""; if (planObj != null) { List <SqlParameter> parameterList = new List <SqlParameter>(); string procName = "sp_T_Planing_Mobile_Insert"; SqlConnection conn = OpenConnection(); SqlTransaction transaction = conn.BeginTransaction(IsolationLevel.Serializable); command = new SqlCommand(procName, conn); command.Transaction = transaction; command.CommandType = CommandType.StoredProcedure; try { T_PlaningMobileDTO planDTO = (T_PlaningMobileDTO)planObj; planDTO.SpecSDate = ConvertX.MMddYY(planDTO.SpecSDate); planDTO.SpecEDate = ConvertX.MMddYY(planDTO.SpecEDate); planDTO.POSDate = ConvertX.MMddYY(planDTO.POSDate); planDTO.POEDate = ConvertX.MMddYY(planDTO.POEDate); planDTO.ActionSDate = ConvertX.MMddYY(planDTO.ActionSDate); planDTO.ActionEDate = ConvertX.MMddYY(planDTO.ActionEDate); parameterList.AddRange(GetParametersExactly(procName, planDTO, transaction).ToArray()); command = new SqlCommand(procName, conn); command.Transaction = transaction; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(parameterList.ToArray()); command.ExecuteNonQuery(); TPID = command.Parameters[0].Value.ToString(); if (coatingRepairObj != null) { T_PlaningCoatingRepairMobileDTO coatingRepairDTo = (T_PlaningCoatingRepairMobileDTO)coatingRepairObj; procName = "sp_T_Planing_CoatingRepair_Mobile_Insert"; parameterList = new List <SqlParameter>(); if (coatingRepairDTo != null) { coatingRepairDTo.TPID = TPID; parameterList.AddRange(GetParametersExactly(procName, coatingRepairDTo, transaction).ToArray()); command = new SqlCommand(procName, conn); command.Transaction = transaction; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(parameterList.ToArray()); command.ExecuteNonQuery(); } } transaction.Commit(); } catch (Exception ex) { if (transaction != null) { transaction.Rollback(); } logger.error("AddFromMobile error :" + ex.ToString()); throw ex; } finally { CloseConnection(); } } return(TPID); }