public ActionResult ShowAllFiles()
        {
            using (var db = new DataBaseDataContext())
            {
                try
                {
                    var uid      = Session["userid"];
                    var files    = db.FILE_DETAILs.Where(m => m.IS_DELETE == null).OrderByDescending(x => x.CREATED_DATE);
                    var fileList = new List <FileDetailModel>();
                    foreach (var f in files)
                    {
                        var nf = new FileDetailModel();
                        nf.FILE_ID          = f.FILE_ID;
                        nf.FILE_NAME        = f.FILE_NAME;
                        nf.CREATED_DATE     = (DateTime)f.CREATED_DATE;
                        nf.ASSIGN_STAFF_ID  = f.ASSIGN_STAFF_ID;
                        nf.ASSIGN_DATE      = f.ASSIGN_DATE;
                        nf.IS_ASSIGN        = f.IS_ASSIGN;
                        nf.COMPLETE_IN_DAYS = f.COMPLETE_IN_DAYS;
                        nf.DEADLINE_DATE    = f.DEADLINE_DATE;
                        nf.IS_PENDING       = f.IS_PENDING;
                        nf.IS_COMPLETED     = f.IS_COMPLETED;
                        nf.CREATED_BY       = f.CREATED_BY;
                        fileList.Add(nf);
                    }
                    ViewBag.AllFiles = fileList;

                    return(View());
                }
                catch (Exception ex)
                {
                }
                return(View());
            }
        }
        public ActionResult Admin()
        {
            var dashbordModel = new AdminDashboardModel();

            using (var db = new DataBaseDataContext())
            {
                try
                {
                    var files    = db.FILE_DETAILs;
                    var fileList = new List <FileDetailModel>();
                    foreach (var f in files)
                    {
                        var nf = new FileDetailModel();
                        nf.FILE_ID          = f.FILE_ID;
                        nf.FILE_NAME        = f.FILE_NAME;
                        nf.CREATED_DATE     = (DateTime)f.CREATED_DATE;
                        nf.ASSIGN_STAFF_ID  = f.ASSIGN_STAFF_ID;
                        nf.ASSIGN_DATE      = f.ASSIGN_DATE;
                        nf.IS_ASSIGN        = f.IS_ASSIGN;
                        nf.COMPLETE_IN_DAYS = f.COMPLETE_IN_DAYS;
                        nf.DEADLINE_DATE    = f.DEADLINE_DATE;
                        nf.IS_PENDING       = f.IS_PENDING;
                        nf.IS_COMPLETED     = f.IS_COMPLETED;
                        nf.CREATED_BY       = f.CREATED_BY;
                        fileList.Add(nf);
                    }

                    dashbordModel.AllFiles = fileList;
                }
                catch (Exception ex)
                {
                }
            }
            return(View(dashbordModel));
        }
        public ActionResult getFIleStaff()
        {
            using (var db = new DataBaseDataContext())
            {
                try
                {
                    var uid      = Session["userid"];
                    var files    = db.FILE_DETAILs.Where((m => m.ASSIGN_STAFF_ID.Equals(Session["userid"]) && m.IS_DELETE == null)).ToList();
                    var fileList = new List <FileDetailModel>();
                    foreach (var f in files)
                    {
                        var nf = new FileDetailModel();
                        nf.FILE_ID          = f.FILE_ID;
                        nf.FILE_NAME        = f.FILE_NAME;
                        nf.CREATED_DATE     = (DateTime)f.CREATED_DATE;
                        nf.ASSIGN_STAFF_ID  = f.ASSIGN_STAFF_ID;
                        nf.ASSIGN_DATE      = f.ASSIGN_DATE;
                        nf.IS_ASSIGN        = f.IS_ASSIGN;
                        nf.COMPLETE_IN_DAYS = f.COMPLETE_IN_DAYS;
                        nf.DEADLINE_DATE    = f.DEADLINE_DATE;
                        nf.IS_PENDING       = f.IS_PENDING;
                        nf.IS_COMPLETED     = f.IS_COMPLETED;
                        nf.CREATED_BY       = f.CREATED_BY;
                        fileList.Add(nf);
                    }

                    return(View(fileList));
                }
                catch (Exception ex)
                {
                }
                return(View());
            }
        }
        public PartialViewResult FileDetails(int fileid)
        {
            using (var db = new DataBaseDataContext())
            {
                try
                {
                    var f = db.FILE_DETAILs.Where(m => m.FILE_ID == fileid).FirstOrDefault();


                    var nf = new FileDetailModel();
                    nf.FILE_ID          = f.FILE_ID;
                    nf.FILE_NAME        = f.FILE_NAME;
                    nf.CREATED_DATE     = (DateTime)f.CREATED_DATE;
                    nf.ASSIGN_STAFF_ID  = f.ASSIGN_STAFF_ID;
                    nf.ASSIGN_DATE      = f.ASSIGN_DATE;
                    nf.IS_ASSIGN        = f.IS_ASSIGN;
                    nf.COMPLETE_IN_DAYS = f.COMPLETE_IN_DAYS;
                    nf.DEADLINE_DATE    = f.DEADLINE_DATE;
                    nf.IS_PENDING       = f.IS_PENDING;
                    nf.IS_COMPLETED     = f.IS_COMPLETED;
                    nf.CREATED_BY       = f.CREATED_BY;
                    ViewBag.Staffs      = (from u in db.USERs where u.RollId == 3 select u).ToList();
                    return(PartialView(nf));
                }
                catch (Exception e)
                {
                    return(null);
                }
            }
        }
        public async Task <ResponseModel> UploadClientData(FileDetailModel client, DataTable table)
        {
            var sp     = new List <SqlParameter>();
            var pararm = new SqlParameter("@ClientId", client.ClientId);

            sp.Add(pararm);
            pararm = new SqlParameter("@ServiceTypeId", client.ServiceTypeId);
            sp.Add(pararm);
            pararm = new SqlParameter("@DeliveryTypeId", client.DeliveryTypeId);
            sp.Add(pararm);
            pararm = new SqlParameter("@FileName", client.FileName);
            sp.Add(pararm);
            pararm = new SqlParameter("@DataTable", SqlDbType.Structured)
            {
                TypeName = "ClientDataArray",
                Value    = table
            };
            sp.Add(pararm);
            pararm = new SqlParameter("@User", client.UserId);
            sp.Add(pararm);
            pararm = new SqlParameter("@compId", client.CompanyId);
            sp.Add(pararm);
            var sql = "uploadClientData @CLIENTID,@ServiceTypeId,@DeliveryTypeId, @FileName,@DataTable,@User,@compId";
            var res = await _context.Database.SqlQuery <ResponseModel>(sql, sp.ToArray()).SingleOrDefaultAsync();

            if (res.ResponseCode == 0)
            {
                res.IsSuccess = true;
            }
            return(res);
        }
        public ActionResult AddNEWFile(FileDetailModel file)
        {
            using (var db = new DataBaseDataContext())
            {
                FILE_DETAIL newfile = new FILE_DETAIL();
                try
                {
                    if ((file.FILE_ID != 0))
                    {
                        newfile           = db.FILE_DETAILs.Where(m => m.FILE_ID == file.FILE_ID).FirstOrDefault();
                        newfile.FILE_NAME = file.FILE_NAME;
                        if (file.ASSIGN_STAFF_ID != null)
                        {
                            newfile.ASSIGN_STAFF_ID = file.ASSIGN_STAFF_ID;
                            newfile.ASSIGN_DATE     = DateTime.Now;
                            newfile.DEADLINE_DATE   = DateTime.Now.AddDays(Convert.ToDouble(file.COMPLETE_IN_DAYS));
                            newfile.IS_ASSIGN       = true;
                            _buss.SendFileAssignedMessage((int)file.ASSIGN_STAFF_ID, file.FILE_NAME);
                        }
                        newfile.CREATED_DATE     = DateTime.Now;
                        newfile.COMPLETE_IN_DAYS = file.COMPLETE_IN_DAYS;
                        newfile.IS_COMPLETED     = false;
                        newfile.IS_PENDING       = true;
                        db.SubmitChanges();
                        Alert("This is success message", NotificationType.success);
                        ViewBag.Staffs = (from u in db.USERs select u).ToList();
                        return(RedirectToAction("index", "dashboard"));
                    }
                    else
                    {
                        newfile.FILE_NAME = file.FILE_NAME;
                        if (file.ASSIGN_STAFF_ID != null)
                        {
                            newfile.ASSIGN_STAFF_ID = file.ASSIGN_STAFF_ID;
                            newfile.ASSIGN_DATE     = DateTime.Now;
                            newfile.DEADLINE_DATE   = DateTime.Now.AddDays(Convert.ToDouble(file.COMPLETE_IN_DAYS));
                            newfile.IS_ASSIGN       = true;
                        }
                        newfile.CREATED_DATE     = DateTime.Now;
                        newfile.COMPLETE_IN_DAYS = file.COMPLETE_IN_DAYS;
                        newfile.IS_COMPLETED     = false;
                        newfile.IS_PENDING       = true;
                        db.FILE_DETAILs.InsertOnSubmit(newfile);
                        db.SubmitChanges();
                        Alert("This is success message", NotificationType.success);
                        ModelState.Clear();
                        ViewBag.Staffs = (from u in db.USERs select u).ToList();
                        return(View());
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(View());
        }
        public async Task <string> PostBegin(
            string id,
            [FromBody] FileDetailModel details,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            Logger.LogInformation($"{JsonConvert.SerializeObject(Request.Headers, Formatting.Indented)}");

            Logger.LogInformation($"Content-Type: {details.ContentType}");
            Logger.LogInformation($"File Name: {details.Name}");
            Logger.LogInformation($"File Length: {details.Length}");

            return(await backend.ChunkedUploadStartAsync(context, id));
        }
Exemple #8
0
        public async Task <IActionResult> UploadFile([FromForm] List <IFormFile> files)
        {
            //either you can pass the list of files in the method or you can initialize them inside the method like the commented line below
            //var files = HttpContext.Request.Form.Files;
            FileDetailModel fileDetail = new FileDetailModel();

            foreach (var file in files)
            {
                var fileType = Path.GetExtension(file.FileName);
                //var ext = file.;
                if (fileType.ToLower() == ".pdf" || fileType.ToLower() == ".jpg" || fileType.ToLower() == ".png" || fileType.ToLower() == ".jpeg")
                {
                    var filePath = _env.ContentRootPath;
                    var docName  = Path.GetFileName(file.FileName);
                    if (file != null && file.Length > 0)
                    {
                        fileDetail.Id           = Guid.NewGuid();
                        fileDetail.DocumentName = docName;
                        fileDetail.DocType      = fileType;
                        fileDetail.DocUrl       = Path.Combine(filePath, "Files", fileDetail.Id.ToString() + fileDetail.DocType);
                        using (var stream = new FileStream(fileDetail.DocUrl, FileMode.Create))
                        {
                            file.CopyToAsync(stream);
                        }

                        var latestFileDetail = fileDetail;
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
            }

            return(Ok());
        }
        public async Task <ActionResult> Upload(FileDetailModel clientDataModel)
        {
            clientDataModel.CompanyId = CurrentUser.CompanyId;
            clientDataModel.UserId    = CurrentUser.UserId;
            if (CurrentUser.UserTypeName.ToLower().Contains("client"))
            {
                clientDataModel.ClientId = CurrentUser.RefKey;
            }
            string excelPath = Server.MapPath(FilePath + "ClientData");

            if (clientDataModel.DataFile != null)
            {
                string FileName = SaveFile(clientDataModel.DataFile, "ClientData");
                clientDataModel.FileName = FileName;
                string conString = string.Empty;
                string extension = Path.GetExtension(clientDataModel.DataFile.FileName);
                switch (extension)
                {
                case ".xls":     //Excel 97-03
                    conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
                    break;

                case ".xlsx":     //Excel 07 or higher
                    conString = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
                    break;
                }
                conString = string.Format(conString, excelPath + "/" + FileName);
                DataTable dtExcelData = new DataTable();
                var       cols        = new List <DataColumn> {
                    new DataColumn("Customer Type", typeof(string)),
                    new DataColumn("Customer Name", typeof(string)),
                    new DataColumn("Customer Contact Number", typeof(string)),
                    new DataColumn("Customer Alt Con Number", typeof(string)),
                    new DataColumn("Customer Email", typeof(string)),
                    new DataColumn("Customer Address Type", typeof(string)),
                    new DataColumn("Customer Address", typeof(string)),
                    new DataColumn("Customer Country", typeof(string)),
                    new DataColumn("Customer State", typeof(string)),
                    new DataColumn("Customer City", typeof(string)),
                    new DataColumn("Customer Pincode", typeof(string)),
                    new DataColumn("Device Category", typeof(string)),
                    new DataColumn("Device Sub Category", typeof(string)),
                    new DataColumn("Device Brand", typeof(string)),
                    new DataColumn("Device Model", typeof(string)),
                    new DataColumn("Device Model No", typeof(string)),
                    new DataColumn("Device Sn", typeof(string)),
                    new DataColumn("DOP", typeof(string)),
                    new DataColumn("Purchase From", typeof(string)),
                    new DataColumn("Device IMEI First", typeof(string)),
                    new DataColumn("Device IMEI Second", typeof(string)),
                    new DataColumn("Device Condition", typeof(string)),
                    new DataColumn("PROBLEM DESCRIPTION", typeof(string)),
                    new DataColumn("ISSUE OCURRING SINCE DATE", typeof(string))
                };

                using (OleDbConnection excel_con = new OleDbConnection(conString))
                {
                    excel_con.Open();
                    string sheet1 = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
                    dtExcelData.Columns.AddRange(cols.ToArray());
                    using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "] where  [Customer Name] is not null", excel_con))
                    {
                        oda.Fill(dtExcelData);
                    }
                    excel_con.Close();
                }
                try
                {
                    var response = await _RepoUploadFile.UploadClientData(clientDataModel, dtExcelData);

                    if (!response.IsSuccess)
                    {
                        System.IO.File.Delete(excelPath + '/' + clientDataModel.FileName);
                    }
                    TempData["response"] = response;
                    return(RedirectToAction("index"));
                }
                catch (Exception ex)
                {
                    if (System.IO.File.Exists(excelPath + '/' + clientDataModel.FileName))
                    {
                        System.IO.File.Delete(excelPath + '/' + clientDataModel.FileName);
                    }
                    return(RedirectToAction("index"));
                }
            }
            return(RedirectToAction("index"));
        }