public FileItResponse AddUpdateUser(string user, string pass, FileItUser userobj)
        {
            var response = new FileItResponse();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var loginUser = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                if (loginUser.Authenticate(pass))
                {
                    var userDb = db.USERS.FirstOrDefault(u => u.USERNAME == userobj.UserName);
                    if (userDb == null)
                    {
                        userDb = new FileItDataLayer.Models.USER();
                    }
                    if (userDb != null)
                    {
                        if (userobj.MergeWithDB(userDb))
                        {
                            db.SaveChanges();
                            response.Success = true;
                        }
                    }
                }
            }
            return(response);
        }
Esempio n. 2
0
        private static string GenerateCabinetId(string cabinetName, ref string CABINETNAMEVALUE)
        {
            var result            = "";
            var bFound            = false;
            int i                 = 0;
            var cabinetNameExists = false;

            //handle long names
            if (cabinetName.Length > 18)
            {
                cabinetName = cabinetName.Substring(0, 18);
            }

            using (var db = new SystemFileitEntities())
            {
                cabinetNameExists = db.CABINETS.Any(c => c.CABINETNAME.Equals(cabinetName, StringComparison.CurrentCultureIgnoreCase));

                while (!bFound && i < 99999)
                {
                    var ticks = DateTime.Now.Ticks.ToString();
                    result = cabinetName.Replace(" ", "") + ticks.Substring(ticks.Length - 5, 5);

                    bFound = !db.CABINETS.Any(c => c.CABINETID.Equals(result, StringComparison.CurrentCultureIgnoreCase));
                    if (cabinetNameExists && bFound)
                    {
                        CABINETNAMEVALUE += ticks.Substring(ticks.Length - 5, 5);
                    }
                    i++;
                }
            }
            return(result);
        }
        public FileItResponse SetCabinetAccess(string user, string pass, string accesstype, string targetuser, string cabinetid, bool allowaccess)
        {
            var response = new FileItResponse();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var cabinet = db.CABINETS.FirstOrDefault(c => c.CABINETID == cabinetid);
                if (cabinet != null)
                {
                    response.Success = cabinet.SetAccess(accesstype, targetuser, allowaccess);
                }
            }
            return(response);
        }
        public Dictionary <string, string> GetCabinets(string user, string pass, string targetuser, bool allavailable)
        {
            var response = new Dictionary <string, string>();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var userObj       = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                var targetUserObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(targetuser, StringComparison.CurrentCultureIgnoreCase));
                if (userObj != null && targetUserObj != null && userObj.Authenticate(pass))
                {
                    response = allavailable ? targetUserObj.AvailableCabinets : targetUserObj.Cabinets;
                }
            }
            return(response);
        }
        public FileItResponse SetUserPassword(string user, string pass, string targetuser, string newpass)
        {
            var response = new FileItResponse();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var userObj       = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                var targetUserObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(targetuser, StringComparison.CurrentCultureIgnoreCase));
                if (userObj != null && targetUserObj != null && userObj.Authenticate(pass))
                {
                    targetUserObj.PASS = newpass;
                    db.SaveChanges();
                    response.Success = true;
                }
            }
            return(response);
        }
        public FileItResponse UploadDocuments(string user, string pass, string cabinetId, DTOs.FileItDocument[] documents)
        {
            var response = new FileItResponse();

            response.FileNameFileItID = new Dictionary <string, string>();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                Debug("Uploading to cabinet: " + cabinetId + " " + documents.Length.ToString() + " docs");
                var cab = db.CABINETS.Single(c => c.CABINETID.Equals(cabinetId, StringComparison.CurrentCultureIgnoreCase));
                response.Success = true;
                documents.ToList().ForEach(d =>
                {
                    var filename = FileItDataLayer.Models.FileItDocument.GetNextFileName();
                    Debug("Got filename: " + filename);
                    var doc = new FileItDataLayer.Models.FileItDocument()
                    {
                        FILENAME    = filename,
                        ARCHIVED    = "N",
                        DELETED     = false,
                        ImageBase64 = d.ImageBase64,
                        EXTENSION   = System.IO.Path.GetExtension(d.FileName).Replace(".", ""),
                        INDEXEDON   = DateTime.Now,
                        PUBLIC      = true,
                        VERSION_NO  = 1,
                        VERSIONID   = "",
                        USERID      = user,
                        STATIONID   = AppGlobal.StationID,
                        BATCHNO     = "BATCH",
                        Indexes     = d.IndexInformation
                    };
                    if (!cab.Add(doc))
                    {
                        Debug("Failed to add doc.");
                        response.Success = false;
                    }
                    else
                    {
                        //TODO: retain the doc id and return
                        response.FileNameFileItID.Add(d.FileName, filename);
                    }
                });
            }
            return(response);
        }
        public FileItResponse Authenticate(string user, string pass)
        {
            var response = new FileItResponse();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var userObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                if (userObj != null)
                {
                    response.Success = userObj.Authenticate(pass);
                }
                else
                {
                    response.Message = "User was not found";
                }
            }
            return(response);
        }
        public FileItResponse DeleteDocument(string user, string pass, string cabinetid, string documentId)
        {
            var response = new FileItResponse();

            response.Documents = new List <DTOs.FileItDocument>();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var userObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                if (userObj != null && userObj.Authenticate(pass))
                {
                    var cabinet = db.CABINETS.Single(c => c.CABINETID.Equals(cabinetid, StringComparison.CurrentCultureIgnoreCase));
                    response.Success = cabinet.DeleteDocument(documentId);
                }
            }

            return(response);
        }
        public FileItResponse GetDocuments(string user, string pass, string cabinetid, List <DTOs.FileItDocumentLookup> lookups, bool includeThumbs)
        {
            var response = new FileItResponse();

            response.Documents = new List <DTOs.FileItDocument>();

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                Debug("Getting user: "******"Getting cabinet" + cabinetid);
                    var cabinet  = db.CABINETS.Single(c => c.CABINETID.Equals(cabinetid, StringComparison.CurrentCultureIgnoreCase));
                    var template = new FileItTemplate();
                    template.ConvertFromTEMPLATE(cabinet.Template);
                    Debug("Getting template" + cabinet.Template);

                    response.Cabinet = new FileItCabinet()
                    {
                        CabinetId   = cabinet.CABINETID,
                        CabinetName = cabinet.CABINETNAME,
                        Template    = template
                    };
                    var result = cabinet.GetDocuments(ConvertLookups(lookups), includeThumbs);
                    result.ToList().ForEach(d =>
                    {
                        response.Documents.Add(new DTOs.FileItDocument()
                        {
                            FileName               = d.FILENAME,
                            ImageBase64            = d.ImageBase64,
                            WebImageBase64         = d.WebImageBase64,
                            WebImageBase64Src      = d.WebImageBase64Src,
                            WebImageThumbBase64    = d.WebImageThumbBase64,
                            WebImageThumbBase64Src = d.WebImageThumbBase64Src,
                            IndexInformation       = d.Indexes
                        });
                    });
                }
            }


            return(response);
        }
        public FileItCabinet GetCabinet(string user, string pass, string cabinetId)
        {
            FileItCabinet response = null;

            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var userObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                if (userObj != null && userObj.Authenticate(pass))
                {
                    var cabinet = db.CABINETS.Single(c => c.CABINETID.Equals(cabinetId));

                    var def      = new List <FileItTemplateDefinition>();
                    var template = new FileItTemplate();
                    template.ConvertFromTEMPLATE(cabinet.Template);
                    response = new FileItCabinet()
                    {
                        CabinetId   = cabinet.CABINETID,
                        CabinetName = cabinet.CABINETNAME,
                        Template    = template
                    };
                }
            }
            return(response);
        }
        public FileItResponse GetDocumentsById(string user, string pass, List <FileItDocumentIdLookup> documentIds, bool includeThumbs, bool includeDeleted)
        {
            var response = new FileItResponse();

            response.Documents = new List <DTOs.FileItDocument>();
            using (var db = new FileItDataLayer.Models.SystemFileitEntities())
            {
                var userObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase));
                if (userObj != null && userObj.Authenticate(pass))
                {
                    Debug("Getting docs by id IN METHOD");
                    //load the lists
                    var cabinets       = new Dictionary <string, List <string> >();
                    var currentCabinet = "";

                    documentIds.ToList().ForEach(d =>
                    {
                        if (!cabinets.ContainsKey(d.CabinetId))
                        {
                            cabinets.Add(d.CabinetId, new List <string>());
                        }
                        cabinets[d.CabinetId].Add(d.DocumentId);
                    });

                    Debug("Looping Cabinets" + cabinets.Count.ToString());
                    cabinets.ToList().ForEach(c =>
                    {
                        Debug("PROCESSING CABINET:" + c.Key + " ITEMS=" + c.Value.Count);
                        Debug("******************");
                        currentCabinet = c.Key;

                        var cabinet = db.CABINETS.Single(cab => cab.CABINETID.Equals(c.Key, StringComparison.CurrentCultureIgnoreCase));
                        if (response.Cabinet == null)
                        {
                            var template = new FileItTemplate();
                            template.ConvertFromTEMPLATE(cabinet.Template);
                            response.Cabinet = new FileItCabinet()
                            {
                                CabinetId   = cabinet.CABINETID,
                                CabinetName = cabinet.CABINETNAME,
                                Template    = template
                            };
                        }
                        Debug("About to get documents: " + cabinet.CABINETNAME + " " + c.Value.Count);
                        //get the documents
                        cabinet.GetDocumentsByIds(c.Value, includeThumbs, includeDeleted).ToList().ForEach(doc =>
                        {
                            Debug("in loop adding docs to response COUNT=" + response.Documents.Count);
                            response.Documents.Add(new DTOs.FileItDocument()
                            {
                                FileName               = doc.FILENAME,
                                ImageBase64            = doc.ImageBase64,
                                WebImageBase64         = doc.WebImageBase64,
                                WebImageBase64Src      = doc.WebImageBase64Src,
                                WebImageThumbBase64    = doc.WebImageThumbBase64,
                                WebImageThumbBase64Src = doc.WebImageThumbBase64Src,
                                IndexInformation       = doc.Indexes
                            });
                        });
                        Debug("Responses loaded: " + response.Documents.Count());
                        response.Success = true;
                    });
                }
            }

            return(response);
        }
Esempio n. 12
0
        public static bool Create(string cabinetName, ref string cabinetId, string username, TEMPLATE template, string dataPath, string cabinetTemplatePath)
        {
            var result = false;
            var cabinetNameValidated = cabinetName;

            //get a valid cabinetId
            //validate cabinet name

            cabinetId = GenerateCabinetId(cabinetName, ref cabinetNameValidated);

            //create all folder paths
            var paths = new List <string>()
            {
                Path.Combine(FileItDataPath, cabinetId),
                Path.Combine(FileItDataPath, cabinetId, "oStore"),
                Path.Combine(FileItDataPath, cabinetId, "tStore"),
                Path.Combine(FileItDataPath, cabinetId, "wStore")
            };

            paths.ToList().ForEach(p =>
            {
                if (!Directory.Exists(p))
                {
                    Directory.CreateDirectory(p);
                }
            });

            //copy the template to the correct location (rename in the process)
            var newCabinetFilePath = Path.Combine(FileItDataPath, cabinetId, cabinetId + ".FILEIT");

            File.Copy(EmptyCabinetFilePath, newCabinetFilePath);

            using (var db = new SystemFileitEntities())
            {
                if (!db.TEMPLATES.Any(t => t.TEMPLATENAME.Equals(template.TEMPLATENAME, StringComparison.CurrentCultureIgnoreCase)))
                {
                    template.DESCRIPTION = "Auto Template From SVC";
                    template.ACCOUNT     = "[Default System Account]";
                    db.TEMPLATES.Add(template);
                    template.TemplateDefinitions.ToList().ForEach(td =>
                    {
                        td.TEMPLATENAME = template.TEMPLATENAME;
                        db.TEMPLATE_DEFINITION.Add(td);
                    });
                    db.SaveChanges();
                }
            }

            //add tables to the empty FILEIT db
            var newCabinet = new CABINET()
            {
                CABINETID       = cabinetId,
                CABINETNAME     = cabinetNameValidated,
                CABINETFULLPATH = newCabinetFilePath,
                ROOTPATH        = Path.Combine(FileItDataPath, cabinetId),
                OSTOREPATH      = Path.Combine(FileItDataPath, cabinetId, "oStore"),
                TSTOREPATH      = Path.Combine(FileItDataPath, cabinetId, "tStore"),
                WSTOREPATH      = Path.Combine(FileItDataPath, cabinetId, "wStore"),
                ACCOUNT         = "Default System Account",
                ADMINISTRATOR   = username,
                DESCRIPTION     = "FileIt Service Created Cabinet",
                TEMPLATENAME    = template.TEMPLATENAME
            };

            newCabinet.CreateTables();

            //create CABINET record
            using (var db = new SystemFileitEntities())
            {
                db.CABINETS.Add(newCabinet);
                newCabinet.SetAccess("user", username, true);
                db.SaveChanges();
            }
            result = true;

            return(result);
        }