Beispiel #1
0
        public async Task SaveDocument(apec_khktdocs_document document)
        {
            try
            {
                if (document.id != 0)
                {
                    var entity = await _documentRepository.GetByIdAsync(document.id).ConfigureAwait(false);

                    entity.document_name        = document.document_name;
                    entity.stage                = document.stage;
                    entity.document_description = document.document_description;
                    entity.created_user         = document.created_user;
                    entity.status               = document.status;
                    entity.approve_date         = document.approve_date;
                    entity.document_extension   = document.document_extension;
                    entity.document_folder_id   = document.document_folder_id;
                    entity.modified_date        = document.modified_date;
                    entity.document_receiver    = document.document_receiver;
                    entity.document_agency      = document.document_agency;

                    await _documentRepository.UpdateAsync(entity).ConfigureAwait(false);

                    return;
                }

                var username = await _userRepository.GetUsersByUserName(document.approver).ConfigureAwait(false);

                var sender = await _userRepository.GetUsersByUserName(document.created_user).ConfigureAwait(false);

                var folder = await _doctypeRepository.GetByIdAsync(document.document_folder_id).ConfigureAwait(false);

                MailSenderDTOs mail = new MailSenderDTOs
                {
                    approver     = username.display_name,
                    requester    = document.created_user,
                    folder       = folder.text,
                    docname      = document.document_name,
                    docdate      = document.created_date,
                    note         = document.document_description,
                    link         = "http://docs.apecgroup.net/Home/Index?folderid=" + document.document_folder_id,
                    approverMail = username.email,
                    sendermail   = sender.email,
                    status       = GetDocDesEnum(document.status)
                };

                await _documentRepository.SaveDocument(document).ConfigureAwait(false);

                await _documentRepository.SendMail(mail).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #2
0
        public async Task <JsonResult> CreateDoc()
        {
            try
            {
                IEnumerable <IFormFile> file = Request.Form.Files;
                string doc_description       = Request.Form["doc_description"].ToString();
                string create_user           = Request.Form["create_user"].ToString();
                string status       = Request.Form["status"].ToString();
                string created_date = Request.Form["created_date"].ToString();
                string doc_folder   = Request.Form["doc_folder"].ToString();
                string doc_approver = Request.Form["doc_approver"].ToString();

                foreach (var item in file)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        //Upload Document
                        item.OpenReadStream().CopyTo(memoryStream);
                        var fileData = memoryStream.ToArray();
                        var fullpath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads", item.FileName);
                        if (System.IO.File.Exists(fullpath))
                        {
                            return(Json(new { status = "fail", message = "Trùng tên file !" }));
                        }
                        System.IO.File.WriteAllBytes(fullpath, fileData);

                        apec_khktdocs_document document = new apec_khktdocs_document
                        {
                            document_description = doc_description,
                            document_extension   = Path.GetExtension(item.FileName),
                            document_name        = Path.GetFileNameWithoutExtension(item.FileName),
                            document_folder_id   = int.Parse(doc_folder),
                            created_user         = create_user,
                            created_date         = Convert.ToDateTime(created_date),
                            status   = int.Parse(status),
                            approver = doc_approver
                        };
                        await _documentService.SaveDocument(document);
                    }
                }

                return(Json(new { status = "success", message = "success" }));
            }
            catch (Exception)
            {
                return(Json(new { status = "fail", message = "fail" }));
            }
        }