コード例 #1
0
        public IActionResult GetUsername()
        {
            try
            {
                string currentUserID = "";
                //string rolename = "";
                //string result = "User not found!!";

                //string userName = "";
                //ClaimsPrincipal currentUser = this.User;
                ////currentUserID = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value;
                //userName = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
                //userName = _httpContextAccessor.HttpContext.User.Identity.Name;
                ////return Ok(currentUserID);

                //Get username from AD
                //currentUserID = Environment.UserName;
                currentUserID = User.Identity.Name;
                //var userName = User.FindFirst("name").Value;
                return(Ok(currentUserID));
            }
            catch (Exception ex)
            {
                _errorlogService.InsertError(Request.GetDisplayUrl(), ControllerContext.ActionDescriptor.ActionName.ToString(), ex.Message, ex.ToString()).ConfigureAwait(false);
                return(StatusCode(500, ex.InnerException));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetGenericPage(string LDAPUser_id)
        {
            try
            {
                string dirJson = await _service.GetFavourite(LDAPUser_id).ConfigureAwait(false);

                return(Ok(dirJson));
            }
            catch (Exception ex)
            {
                await _errorlogService.InsertError(Request.GetDisplayUrl(), ControllerContext.ActionDescriptor.ActionName.ToString(), ex.Message, ex.ToString()).ConfigureAwait(false);

                return(StatusCode(500, ex.InnerException));
            }
        }
コード例 #3
0
        public async Task <IActionResult> GetDirDoc(int id, string username)
        {
            try
            {
                string dirJson = await _dirService.GetDirectoryAsync(id, username).ConfigureAwait(false);

                return(Ok(dirJson));
            }
            catch (Exception ex)
            {
                await _errorlogService.InsertError(Request.GetDisplayUrl(), ControllerContext.ActionDescriptor.ActionName.ToString(), ex.Message, ex.ToString());

                return(StatusCode(500, ex.InnerException));
            }
        }
コード例 #4
0
        public async Task <IActionResult> GetMenu(string menuType)
        {
            try
            {
                string MenuJson = await _menuService.GetMainMenuAsync(menuType).ConfigureAwait(false);

                return(Ok(MenuJson));
            }
            catch (Exception ex)
            {
                await _errorlogService.InsertError(Request.GetDisplayUrl(), ControllerContext.ActionDescriptor.ActionName.ToString(), ex.Message, ex.ToString()).ConfigureAwait(false);

                return(StatusCode(500, ex.InnerException));
            }
        }
コード例 #5
0
        public async Task <IActionResult> AddRole(Roles role, CancellationToken cancellationToken)
        {
            try
            {
                //Roles role = new Roles()
                //{
                //    RoleName = rolename,
                //    CreatedBy = "Basha",
                //    ModifiedBy = "Basha",
                //    CreatedDate = DateTime.Now,
                //    ModifiedDate = DateTime.Now
                //};

                await _repo.AddRole(role, cancellationToken);

                return(Ok("Role added successfully"));
            }
            catch (Exception ex)
            {
                await _errorlogService.InsertError(Request.GetDisplayUrl(), ControllerContext.ActionDescriptor.ActionName.ToString(), ex.Message, ex.ToString()).ConfigureAwait(false);

                return(StatusCode(500, ex.InnerException));
            }
        }
コード例 #6
0
        //  public async Task Post(IFormFile file,  Int32 ID)
        public async Task <string> UploadDocument(int id, DocumentUp Model, IFormFile files, CancellationToken cancellationToken) // DocumentUpload Model, List<IFormFile> files, CancellationToken cancellationToken, , string Image
        {
            try
            {
                //File upload not allowed to in root folder
                if (Model.Parent_id == 0)
                {
                    return("Select a sub folder to upload file.");
                }

                int result = 0;
                if (id != 0 || files == null) //Delete // edit
                {
                    if (files == null)        // update existing record
                    {
                        DocumentDto UpdateModel = new DocumentDto()
                        {
                            DocName         = Model.DocName,
                            DocDescription  = Model.DocDescription,
                            Fk_Directory_id = Model.Parent_id,
                            CreatedBy       = Model.CreatedBy
                        };

                        result = await _formService.UpdateDocument(id, UpdateModel, cancellationToken).ConfigureAwait(false);


                        if (result == 1)
                        {
                            return("Document Updated");
                        }
                        else
                        {
                            return("Document Not Found!");
                        }
                    }
                    else
                    {
                        result = await _formService.DeleteDocument(id, Model.CreatedBy, cancellationToken).ConfigureAwait(false);

                        if (result == 0)
                        {
                            return("Document not found!");
                        }
                    }
                }

                // 1 . Check/Create Directory & set the File upload path
                var RootDir     = Configuration.GetValue <string>("RootDirectory");
                var MaxFileSize = Configuration.GetValue <int>("MaxFileSize");

                string dirJson = await _formService.GetDocumentUpload(Model.Parent_id, RootDir).ConfigureAwait(false);

                string doctype  = "";
                long   Filesize = 0;
                //var filePath = Path.Combine(_environment.ContentRootPath, dirJson);
                var filePath = _environment.ContentRootPath;

                //2. Upload the files in the set path

                if (files != null)
                {
                    Filesize = files.Length;
                    FileInfo fi = new FileInfo(files.FileName);
                    doctype = fi.Extension;

                    var filePaths = new List <string>();
                    if (files.Length > 0 && files.Length < MaxFileSize)
                    {
                        filePaths.Add(filePath);
                        var fileNameWithPath = string.Concat(filePath, "\\", Model.DocName, doctype);
                        using (var stream = new FileStream(fileNameWithPath, FileMode.Create))
                        {
                            await files.CopyToAsync(stream);
                        }

                        Model.DocPath = fileNameWithPath;
                    }
                }
                else
                {
                    // update the name without uploading
                    doctype = doctype.Replace(".", "");
                    DocumentDto AddModel = new DocumentDto()
                    {
                        //id = Model.id,
                        DocName         = Model.DocName,
                        DocDescription  = Model.DocDescription,
                        Fk_Directory_id = Model.Parent_id,
                        DocPath         = filePath,
                        DocType         = doctype,
                        DocSize         = 0,
                        CreatedBy       = Model.CreatedBy
                    };

                    result = await _formService.AddDocument(AddModel, cancellationToken).ConfigureAwait(false);

                    ////////////////////
                    if (result == 1)
                    {
                        return("Document Details Updated");
                    }
                    else
                    {
                        return("Document size exceeds maximum limit " + MaxFileSize / 1000000 + " MB");
                    }
                }

                doctype = doctype.Replace(".", "");

                DocumentDto DocModel = new DocumentDto()
                {
                    //id = Model.id,
                    DocName         = Model.DocName,
                    DocDescription  = Model.DocDescription,
                    Fk_Directory_id = Model.Parent_id,
                    DocPath         = Model.DocPath,
                    DocType         = doctype,
                    DocSize         = (int)Filesize,
                    CreatedBy       = Model.CreatedBy
                };

                result = await _formService.AddDocument(DocModel, cancellationToken).ConfigureAwait(false);

                return("Document Uploaded Successfully");
            }
            catch (Exception ex)
            {
                await _errorlogService.InsertError(Request.GetDisplayUrl(), ControllerContext.ActionDescriptor.ActionName.ToString(), ex.Message, ex.ToString()).ConfigureAwait(false);

                return(ex.ToString());
            }
        }