Esempio n. 1
0
        public HttpResponseMessage Add()
        {
            T_Planing_WeatherCollectionMobileBAL mobileBal = new T_Planing_WeatherCollectionMobileBAL();
            ResposeType         response   = new ResposeType();
            HttpResponseMessage mapMessage = null;

            T_Planing_WeatherCollectionMobileDTO mobileDto = null;

            try
            {
                var context = HttpContext.Current;
                //context.Response.ContentType = "multipart/form-data";

                mobileDto = ConvertX.GetReqeustFormExactly <T_Planing_WeatherCollectionMobileDTO>();

                string UserID = context.Request.Form["UserID"];
                if (ObjUtil.isEmpty(UserID))
                {
                    throw new Exception("UserID is require");
                }
                mobileDto.CreateBy = UserID;
                mobileDto.UpdateBy = UserID;

                logger.debug("api/PlanWeatherCollection Add dto:" + mobileDto.ToString());
                response.statusCode = mobileBal.AddFromMobile(mobileDto);
                if (response.statusCode)
                {
                    response.statusText = "Success";
                }
            }
            catch (Exception ex)
            {
                logger.error("api/PlanWeatherCollection Add error:" + ex.ToString());
                response.statusText = ex.ToString();
            }

            mapMessage = Request.CreateResponse(HttpStatusCode.OK, response);
            return(mapMessage);
        }
        public bool AddFromMobile(object data)
        {
            try
            {
                T_Planing_WeatherCollectionMobileDTO obj = (T_Planing_WeatherCollectionMobileDTO)data;
                if (obj != null)
                {
                    List <SqlParameter> parameterList = new List <SqlParameter>();

                    string        procName = "sp_T_Planing_Action_WeatherCollection_Insert_Mobile";
                    SqlConnection conn     = OpenConnection();

                    isCan           = true;
                    obj.CollectDate = ConvertX.MMddYY(obj.CollectDate);
                    command         = new SqlCommand(procName, conn);

                    command.CommandType = CommandType.StoredProcedure;

                    parameterList.AddRange(GetParametersExactly(procName, obj).ToArray());
                    command.Parameters.AddRange(parameterList.ToArray());

                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                isCan = false;

                throw new Exception(ex.Message);
            }
            finally
            {
                CloseConnection();
            }
            return(isCan);
        }