Exemplo n.º 1
0
        public async Task <IActionResult> UpdateDocMenuA5Edit([FromBody] ModelMenuA5 model)
        {
            IActionResult _result = BadRequest();

            ModelResponseA5Message e = await _IDocMenuAService.UpdateDocMenuA5EditAsync(model);

            if (e.Status)
            {
                _result = Ok(e);

                try
                {
                    await _IMailTemplateService.MailTemplate8Async(model.projectnumber, e.filebase64);
                }
                catch (Exception ex)
                {
                    //Keep
                }
            }
            else
            {
                _result = BadRequest();
            }

            return(_result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateDocMenuA5Edit([FromBody] ModelMenuA5 model)
        {
            var    requestUri = $"{_WebApiModel.BaseURL}/{"PrivateDocMenuA"}/{"UpdateDocMenuA5Edit"}";
            string authHeader = HttpContext.Request?.Headers["Authorization"];

            if (authHeader != null && authHeader.StartsWith("Bearer"))
            {
                BearerToken = authHeader.Substring("Bearer ".Length).Trim();
            }
            var response = await HttpRequestFactory.Post(requestUri, BearerToken, model);

            switch (response.StatusCode)
            {
            case HttpStatusCode.Unauthorized:
                return(Unauthorized(response.ContentAsString()));

            case HttpStatusCode.BadRequest:
                return(BadRequest(response.ContentAsString()));

            case HttpStatusCode.OK:
                return(Ok(response.ContentAsString()));

            default:
                return(StatusCode(500));
            }
        }
Exemplo n.º 3
0
        public async Task <ModelResponseA5Message> AddDocMenuA5Async(ModelMenuA5 model)
        {
            var cultureInfo = new CultureInfo("en-GB");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            ModelResponseA5Message resp = new ModelResponseA5Message();

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("sp_doc_menu_a5", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@doc_date", SqlDbType.DateTime).Value               = model.docdate.ToString("yyyy-MM-dd");
                    cmd.Parameters.Add("@project_number", SqlDbType.VarChar, 20).Value      = ParseDataHelper.ConvertDBNull(model.projectnumber);
                    cmd.Parameters.Add("@project_head_name", SqlDbType.VarChar, 200).Value  = ParseDataHelper.ConvertDBNull(model.projectheadname);
                    cmd.Parameters.Add("@position_name_thai", SqlDbType.VarChar, 200).Value = ParseDataHelper.ConvertDBNull(model.positionnamethai);
                    cmd.Parameters.Add("@faculty_name", SqlDbType.VarChar, 200).Value       = ParseDataHelper.ConvertDBNull(model.facultyname);
                    cmd.Parameters.Add("@project_name_thai", SqlDbType.VarChar, 200).Value  = ParseDataHelper.ConvertDBNull(model.projectnamethai);
                    cmd.Parameters.Add("@project_name_eng", SqlDbType.VarChar, 200).Value   = ParseDataHelper.ConvertDBNull(model.projectnameeng);
                    cmd.Parameters.Add("@accept_type_name", SqlDbType.VarChar, 200).Value   = ParseDataHelper.ConvertDBNull(model.accepttypenamethai);
                    cmd.Parameters.Add("@conclusion_date", SqlDbType.DateTime).Value        = Convert.ToDateTime(model.conclusiondate);
                    cmd.Parameters.Add("@file1name", SqlDbType.VarChar, 200).Value          = ParseDataHelper.ConvertDBNull(model.file1name);

                    cmd.Parameters.Add("@create_by", SqlDbType.VarChar, 50).Value = Encoding.UTF8.GetString(Convert.FromBase64String(model.createby));

                    SqlParameter rStatus = cmd.Parameters.Add("@rStatus", SqlDbType.Int);
                    rStatus.Direction = ParameterDirection.Output;
                    SqlParameter rMessage = cmd.Parameters.Add("@rMessage", SqlDbType.NVarChar, 500);
                    rMessage.Direction = ParameterDirection.Output;
                    SqlParameter rDocId = cmd.Parameters.Add("@rDocId", SqlDbType.Int);
                    rDocId.Direction = ParameterDirection.Output;

                    await cmd.ExecuteNonQueryAsync();

                    if ((int)cmd.Parameters["@rStatus"].Value > 0)
                    {
                        resp.Status = true;

                        model_rpt_3_file rpt = await _IDocMenuReportRepository.GetReportR3Async((int)cmd.Parameters["@rDocId"].Value);

                        resp.filename   = rpt.filename;
                        resp.filebase64 = rpt.filebase64;
                    }
                    else
                    {
                        resp.Message = (string)cmd.Parameters["@rMessage"].Value;
                    }
                }
                conn.Close();
            }
            return(resp);
        }
Exemplo n.º 4
0
        private async Task <ModelMenuA5> GetMenuA5DataEditAsync(string ProjectNumber, string userid, ModelPermissionPage permission)
        {
            string user_id = Encoding.UTF8.GetString(Convert.FromBase64String(userid));

            string sql = "SELECT TOP(1)* FROM Doc_MenuA5 " +
                         "WHERE project_number='" + ProjectNumber + "' ORDER BY doc_id DESC";

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (SqlCommand command = new SqlCommand(sql, conn))
                {
                    SqlDataReader reader = await command.ExecuteReaderAsync();

                    if (reader.HasRows)
                    {
                        ModelMenuA5 e = new ModelMenuA5();
                        while (await reader.ReadAsync())
                        {
                            e.docid              = reader["doc_id"].ToString();
                            e.projectnumber      = reader["project_number"].ToString();
                            e.projectheadname    = reader["project_head_name"].ToString();
                            e.positionnamethai   = reader["position_name_thai"].ToString();
                            e.facultyname        = reader["faculty_name"].ToString();
                            e.projectnamethai    = reader["project_name_thai"].ToString();
                            e.projectnameeng     = reader["project_name_eng"].ToString();
                            e.accepttypenamethai = reader["accept_type_name"].ToString();
                            e.conclusiondate     = Convert.ToDateTime(reader["conclusion_date"]).ToString("dd/MM/yyyy");
                            e.file1name          = reader["file1name"].ToString();
                            e.createby           = reader["create_by"].ToString();

                            //Default Edit False
                            e.editenable = false;
                            if (permission.edit == true)
                            {
                                if (user_id == reader["create_by"].ToString())
                                {
                                    e.editenable = true;
                                }
                            }
                        }
                        return(e);
                    }
                }
                conn.Close();
            }
            return(null);
        }
Exemplo n.º 5
0
        public async Task <ModelResponseA5Message> UpdateDocMenuA5EditAsync(ModelMenuA5 model)
        {
            model.docdate        = DateTime.Now;
            model.file1name      = (string.IsNullOrEmpty(model.file1base64)) ? model.file1name : GenerateToken.GetGuid() + Path.GetExtension(model.file1name);
            model.conclusiondate = Convert.ToDateTime(model.conclusiondate.Substring(0, 10)).ToString("yyyy-MM-dd");

            var resp = await _IDocMenuA5Repository.UpdateDocMenuA5EditAsync(model);

            if (resp.Status)
            {
                if (!string.IsNullOrEmpty(model.file1base64))
                {
                    ServerDirectorys.SaveFileFromBase64(_IEnvironmentConfig.PathDocument, FolderDocument.menuA5, model.file1name, model.file1base64);
                }
            }

            return(resp);
        }