Пример #1
0
        public bool RemoveTag(int idTags, int recordID)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                WorkLinqToSql.Tag tag = (from t in context.Tags where t.Id == idTags select t).Single <WorkLinqToSql.Tag>();

                var machineTag = from mt in context.MachineTags where (mt.TagID == tag.Id) && (mt.MachineID == recordID) select mt;

                foreach (WorkLinqToSql.MachineTag mt in machineTag)
                {
                    context.MachineTags.DeleteOnSubmit(mt);
                }
                context.MachineTags.Context.SubmitChanges();

                var otherTagMachine = from mt in context.MachineTags where mt.TagID == tag.Id select mt;
                if (otherTagMachine.Count() == 0)
                {
                    context.Tags.DeleteOnSubmit(tag);
                    context.Tags.Context.SubmitChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public bool CreateFile(File file)
        {
            try
            {
                CatalogDatabaseDataContext context  = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Document     document = new WorkLinqToSql.Document();
                document.UserAuthor   = file.AuthorID;
                document.Status       = (int)Record.StatusType.PREMODERATION;
                document.MachineID    = file.RecordID;
                document.PathToFile   = file.PachToFile;
                document.DocumentName = file.DocumentName;
                document.DocumentType = file.DocumentType;
                document.FileName     = file.FileName;
                document.FileType     = file.FileType;
                document.Size         = file.Size;
                document.MachineID    = file.RecordID;

                context.Document.InsertOnSubmit(document);
                context.Document.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        public bool RemoveSpecifications(int idSpecifications)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                WorkLinqToSql.Specification specification = (from s in context.Specifications where s.Id == idSpecifications select s).Single <WorkLinqToSql.Specification>();

                var macnineSpecifications = from ms in context.MachineSpecifications where ms.SpecificationID == specification.Id select ms;

                foreach (WorkLinqToSql.MachineSpecification ms in macnineSpecifications)
                {
                    context.MachineSpecifications.DeleteOnSubmit(ms);
                }
                context.MachineSpecifications.Context.SubmitChanges();

                context.Specifications.DeleteOnSubmit(specification);
                context.Specifications.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        public bool CreateTag(CatalogAppMVC.Models.Tag tagModel, int recordID)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Tag          tag     = new WorkLinqToSql.Tag();
                tag.Name = tagModel.Name;

                var tagsInBase = from t in context.Tags where t.Name == tagModel.Name select t;
                if (tagsInBase.Count() > 0)
                {
                    tag = tagsInBase.First();
                }
                else
                {
                    context.Tags.InsertOnSubmit(tag);
                    context.Tags.Context.SubmitChanges();
                }

                WorkLinqToSql.MachineTag machineTag = new MachineTag();

                machineTag.MachineID = recordID;
                machineTag.Tag       = tag;

                context.MachineTags.InsertOnSubmit(machineTag);
                context.MachineTags.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #5
0
        public bool CreateSpecifications(Specification specificationModel, int recordID)
        {
            try
            {
                CatalogDatabaseDataContext         context              = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Specification        specification        = new WorkLinqToSql.Specification();
                WorkLinqToSql.MachineSpecification machinespecification = new MachineSpecification();

                specification.Name  = specificationModel.Name;
                specification.Value = specificationModel.Value;

                machinespecification.MachineID     = recordID;
                machinespecification.Specification = specification;

                context.Specifications.InsertOnSubmit(specification);
                context.MachineSpecifications.InsertOnSubmit(machinespecification);


                context.Specifications.Context.SubmitChanges();
                context.MachineSpecifications.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #6
0
        public bool UpdateMachinery(Record record)
        {
            try
            {
                CatalogDatabaseDataContext context   = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Machinery    machinery = (from m in context.Machineries where m.Id == record.ID select m).Single <WorkLinqToSql.Machinery>();

                machinery.Description = record.Description;
                machinery.Status      = (int)record.Status;
                machinery.Category    = record.CategoryID;
                machinery.UserAuthor  = record.UserAuthorID;
                context.Machineries.Context.SubmitChanges();

                foreach (Specification sp in record.Specifications)
                {
                    if (!UpdateSpecifications(sp))
                    {
                        throw new Exception("Ошибка обновления спецификации");
                    }
                }
                if (record.Tags != null)
                {
                    foreach (Tag tag in record.Tags)
                    {
                        UpdateTag(tag);
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #7
0
        public bool RemoveCatalogCategories(int idCatalogCategories)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                WorkLinqToSql.CatalogCategory category = (from c in context.CatalogCategories where c.Id == idCatalogCategories select c).Single <WorkLinqToSql.CatalogCategory>();

                if (category.Name == "Others")
                {
                    return(false);
                }

                var mandatSpecifications = from ms in context.MandatSpecificCatalogCategories where ms.CatalogCategoryID == category.Id select ms;
                foreach (var ms in mandatSpecifications)
                {
                    context.MandatSpecificCatalogCategories.DeleteOnSubmit(ms);
                }
                context.MandatSpecificCatalogCategories.Context.SubmitChanges();

                var otherCategory   = from c in context.CatalogCategories where c.Name == "Others" select c;
                int otherCategoryID = 0;
                if (otherCategory.Count() == 0)
                {
                    otherCategoryID = CreateCatalogCategories(new Category()
                    {
                        Name = "Others"
                    });
                }
                else
                {
                    otherCategoryID = otherCategory.Single <CatalogCategory>().Id;
                }

                var machineries = from machinery in category.Machineries select machinery;
                foreach (var machinery in machineries)
                {
                    machinery.Category = otherCategoryID;
                }

                var accesses = from acc in category.AccessCatalogCategories select acc;
                foreach (var acc in accesses)
                {
                    context.AccessCatalogCategories.DeleteOnSubmit(acc);
                }
                context.AccessCatalogCategories.Context.SubmitChanges();
                context.CatalogCategories.DeleteOnSubmit(category);
                context.CatalogCategories.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #8
0
        public bool UpdateTag(CatalogAppMVC.Models.Tag tagModel)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Tag          tag     = (from t in context.Tags where t.Id == tagModel.ID select t).Single <WorkLinqToSql.Tag>();

                tag.Name = tagModel.Name;
                context.MachineTags.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #9
0
        public void RemoveMandatSpecification(int specificationID)
        {
            try
            {
                CatalogDatabaseDataContext  context       = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Specification specification = new WorkLinqToSql.Specification();

                var mSpecification = (from s in context.MandatSpecificCatalogCategories where (s.SpecificationID == specificationID) select s).Single();


                context.MandatSpecificCatalogCategories.DeleteOnSubmit(mSpecification);
                context.MandatSpecificCatalogCategories.Context.SubmitChanges();
            }
            catch
            {
            }
        }
Пример #10
0
        public bool RemoveAccess(AccessRoleCategory accessModel)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                WorkLinqToSql.AccessCatalogCategories access = (from acc in context.AccessCatalogCategories where (acc.CategoryID == accessModel.CategoryID) && (acc.RoleID == accessModel.RoleID) select acc).Single();

                context.AccessCatalogCategories.DeleteOnSubmit(access);
                context.AccessCatalogCategories.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #11
0
        public bool UpdateSpecifications(Specification specificationModel)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                WorkLinqToSql.Specification specification = (from s in context.Specifications where s.Id == specificationModel.ID select s).Single <WorkLinqToSql.Specification>();
                specification.Name  = specificationModel.Name;
                specification.Value = specificationModel.Value;

                context.Specifications.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #12
0
        public bool RemoveMachinery(int recordID)
        {
            try
            {
                CatalogDatabaseDataContext context   = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.Machinery    machinery = (from m in context.Machineries where m.Id == recordID select m).Single <WorkLinqToSql.Machinery>();

                var specificationsID = from s in context.MachineSpecifications where s.MachineID == machinery.Id select s.SpecificationID;
                if (specificationsID.Count() > 0)
                {
                    foreach (int spID in specificationsID)
                    {
                        RemoveSpecifications(spID);
                    }
                }
                var tagsID = from t in context.MachineTags where t.MachineID == machinery.Id select t.TagID;
                if (tagsID.Count() > 0)
                {
                    foreach (int tagID in tagsID)
                    {
                        RemoveTag(tagID, machinery.Id);
                    }
                }
                var filesID = from f in context.Document where f.MachineID == machinery.Id select f.Id;
                if (filesID.Count() > 0)
                {
                    foreach (int fileID in filesID)
                    {
                        RemoveFile(fileID);
                    }
                }

                context.Machineries.DeleteOnSubmit(machinery);
                context.Machineries.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #13
0
        public bool UpdateAccess(AccessRoleCategory accessModel)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                WorkLinqToSql.AccessCatalogCategories access = (from acc in context.AccessCatalogCategories where (acc.CategoryID == accessModel.CategoryID) && (acc.RoleID == accessModel.RoleID) select acc).Single();
                access.R = accessModel.CanRead;
                access.W = accessModel.CanWrite;
                access.F = accessModel.CanDownloadFile;

                context.AccessCatalogCategories.Context.SubmitChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #14
0
        public bool UpdateCatalogCategories(Category categoryModel)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                var categoryNames = from cat in context.CatalogCategories select cat.Name;
                if (!categoryNames.Contains(categoryModel.Name))
                {
                    WorkLinqToSql.CatalogCategory category = (from c in context.CatalogCategories where c.Id == categoryModel.ID select c).Single <WorkLinqToSql.CatalogCategory>();
                    category.Name = categoryModel.Name;
                    context.CatalogCategories.Context.SubmitChanges();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #15
0
        public void CreateMandatSpecification(Specification specificationModel, int categoryID)
        {
            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();
                WorkLinqToSql.MandatSpecificCatalogCategory mSpecification = new WorkLinqToSql.MandatSpecificCatalogCategory();
                WorkLinqToSql.Specification Specification = new WorkLinqToSql.Specification();

                Specification.Name  = specificationModel.Name;
                Specification.Value = "-";
                context.Specifications.InsertOnSubmit(Specification);
                context.Specifications.Context.SubmitChanges();

                mSpecification.CatalogCategoryID = categoryID;
                mSpecification.SpecificationID   = Specification.Id;
                context.MandatSpecificCatalogCategories.InsertOnSubmit(mSpecification);
                context.MandatSpecificCatalogCategories.Context.SubmitChanges();
            }
            catch
            {
            }
        }
Пример #16
0
        public int CreateMachinery(Record record)
        {
            Machinery machinery = new Machinery();

            try
            {
                CatalogDatabaseDataContext context = new WorkLinqToSql.CatalogDatabaseDataContext();

                machinery.title       = record.Name;
                machinery.Description = record.Description;
                machinery.Status      = (int)Record.StatusType.PREMODERATION;
                machinery.Category    = record.CategoryID;
                machinery.UserAuthor  = record.UserAuthorID;
                context.Machineries.InsertOnSubmit(machinery);
                context.Machineries.Context.SubmitChanges();

                foreach (Specification sp in record.Specifications)
                {
                    if (!CreateSpecifications(sp, machinery.Id))
                    {
                        throw new Exception("Невожно создать спецификацию");
                    }
                }
                if (record.Tags != null)
                {
                    foreach (Tag tag in record.Tags)
                    {
                        CreateTag(tag, machinery.Id);
                    }
                }
            }
            catch
            {
                return(0);
            }
            return(machinery.Id);
        }