Beispiel #1
0
 public static bool IsValidToken(string token)
 {
     using (THEntities db = new THEntities())
     {
         string encryptToken = EncryptString(token);
         return(db.sys_user.Any(r => r.user_Deleted == null && r.token == encryptToken));
     }
 }
Beispiel #2
0
        //-- Save upload document --//
        public static async Task <List <sm_doc> > SaveUploadImage(THEntities db, string documentName, int tableID, int recordID, List <string> base64)
        {
            List <sm_doc> documents = new List <sm_doc>();

            if (base64 != null)
            {
                foreach (var image in base64)
                {
                    using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(image)))
                    {
                        string pathForSavingToDB = "", imageNameForSavingToDB = "";
                        using (Bitmap bm = new Bitmap(ms))
                        {
                            string path             = "";
                            string uploadFolderName = "uploads";
                            path = HttpContext.Current.Server.MapPath(@"~\" + uploadFolderName);
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            string currentYear = DateTime.Now.Year.ToString();
                            path += @"\" + currentYear;
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            string currentMonth = DateTime.Now.Month > 9 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month;
                            path += @"\" + currentMonth;

                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            var createImageUniqueName = recordID + "_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmssfff") + ".jpg";
                            bm.Save(path + @"\" + createImageUniqueName);

                            imageNameForSavingToDB = documentName + "_" + createImageUniqueName;
                            pathForSavingToDB      = uploadFolderName + "/" + currentYear + "/" + currentMonth + "/" + createImageUniqueName;
                        }
                        var document = new sm_doc();
                        document.name             = imageNameForSavingToDB;
                        document.tableID          = tableID;
                        document.docs_CreatedDate = DateTime.Now;
                        document.value            = recordID.ToString();
                        document.path             = pathForSavingToDB;
                        db.sm_doc.Add(document);
                        await db.SaveChangesAsync();

                        documents.Add(document);
                    }
                }
            }
            return(documents);
        }
Beispiel #3
0
 public static UserProfileViewDTO GetUserProfile(string token)
 {
     using (THEntities db = new THEntities())
     {
         string             encryptToken = EncryptString(token);
         var                user         = db.sys_user.FirstOrDefault(x => x.user_Deleted == null && x.token == encryptToken);
         UserProfileViewDTO userProfile  = MapDBClassToDTO <sys_user, UserProfileViewDTO>(user);
         return(userProfile);
     }
 }
Beispiel #4
0
        public static async Task <List <sm_doc> > SaveUploadImage(THEntities db, int tableID, int recordID, List <string> base64)
        {
            List <sm_doc> documents = new List <sm_doc>();

            if (base64 != null)
            {
                foreach (var image in base64)
                {
                    using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(image)))
                    {
                        string pathForSavingToDB = "", imageNameForSavingToDB = "";
                        using (Bitmap bm = new Bitmap(ms))
                        {
                            //string path = "";
                            string year  = DateTime.Now.Year.ToString();
                            string month = DateTime.Now.Month > 9 ? DateTime.Now.Month.ToString() : "0" + DateTime.Now.Month;

                            /*
                             * path = ConstantHelper.UPLOAD_FOLDER + @"\" + year + @"\" + month;
                             * path = HttpContext.Current.Server.MapPath(@"~\" + path);
                             * if (!Directory.Exists(path))
                             *  Directory.CreateDirectory(path);
                             * var createImageUniqueName = $"{tableID}_{recordID}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff")}.jpg";
                             * bm.Save(path + @"\" + createImageUniqueName);
                             * bm.Save(@"C:\uploads\" + createImageUniqueName);
                             */
                            var createImageUniqueName = $"{tableID}_{recordID}_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff")}.jpg";
                            var uploadPath            = WebConfigurationManager.AppSettings["uploadPath"].ToString();
                            uploadPath += ConstantHelper.UPLOAD_FOLDER + @"\" + year + @"\" + month;
                            if (!Directory.Exists(uploadPath))
                            {
                                Directory.CreateDirectory(uploadPath);
                            }
                            bm.Save(uploadPath + @"\" + createImageUniqueName);

                            imageNameForSavingToDB = createImageUniqueName;
                            pathForSavingToDB      = $"{ConstantHelper.UPLOAD_FOLDER}/{year}/{month}/{createImageUniqueName}";
                        }
                        var document = new sm_doc();
                        document.name             = imageNameForSavingToDB;
                        document.tableID          = tableID;
                        document.docs_CreatedDate = DateTime.Now;
                        document.value            = recordID.ToString();
                        document.path             = pathForSavingToDB;
                        db.sm_doc.Add(document);
                        await db.SaveChangesAsync();

                        documents.Add(document);
                    }
                }
            }
            return(documents);
        }
Beispiel #5
0
        //-> Get Document
        public static List <DocumentViewDTO> GetDocuments(THEntities db, int tableID, int value)
        {
            List <DocumentViewDTO> documentViews = new List <DocumentViewDTO>();
            IQueryable <sm_doc>    documents     = from d in db.sm_doc
                                                   where d.docs_Deleted == null && d.tableID == tableID && d.value == value.ToString()
                                                   orderby d.id ascending
                                                   select d;

            foreach (var document in documents)
            {
                var mappingDTO = MappingHelper.MapDBClassToDTO <sm_doc, DocumentViewDTO>(document);
                //documentViews.Add(MappingHelper.MapDBClassToDTO<sm_doc, DocumentViewDTO>(document));
                mappingDTO.path = WebConfigurationManager.AppSettings["baseURL"].ToString() + mappingDTO.path;
                documentViews.Add(mappingDTO);
            }

            return(documentViews);
        }
Beispiel #6
0
 public ItemGroupRepository()
 {
     db = new THEntities();
 }
Beispiel #7
0
 public SaleOrderRepository()
 {
     db = new THEntities();
 }
Beispiel #8
0
 public UserRepository()
 {
     db = new THEntities();
 }
 public SlideShowRepository()
 {
     db = new THEntities();
 }
Beispiel #10
0
 public CustomerRepository()
 {
     db = new THEntities();
 }
Beispiel #11
0
 public DocumentRepository()
 {
     db = new THEntities();
 }
Beispiel #12
0
 public WarehouseRepository()
 {
     db = new THEntities();
 }
Beispiel #13
0
 public invoiceRepo()
 {
     db = new THEntities();
 }