Beispiel #1
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);
        }
Beispiel #2
0
        //Методы для работы с БД

        public static Record GetRecord(int recordID)
        {
            IRepository repository = new Repository();
            Record      record     = null;

            try
            {
                WorkLinqToSql.Machinery mach = (from m in repository.Machinerys where m.Id == recordID select m).Single <WorkLinqToSql.Machinery>();
                record = repository.ToRecord(mach);
                if (record.Tags == null)
                {
                    record.Tags = new List <Tag>();
                }
                if (record.Files == null)
                {
                    record.Files = new List <File>();
                }
                if (record.Specifications == null)
                {
                    record.Specifications = new List <Specification>();
                }
            }
            catch
            {
                return(null);
            }
            return(record);
        }
Beispiel #3
0
 public bool UpdateStatusMachinery(Record.StatusType statusNew, int recordID)
 {
     try
     {
         WorkLinqToSql.CatalogDatabaseDataContext context = new CatalogDatabaseDataContext();
         WorkLinqToSql.Machinery machinery = (from m in context.Machineries where m.Id == recordID select m).Single <WorkLinqToSql.Machinery>();
         machinery.Status = (int)statusNew;
         context.Machineries.Context.SubmitChanges();
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Beispiel #4
0
        public Record ToRecord(WorkLinqToSql.Machinery machinery)
        {
            Record record = new Record();

            record.SetID(machinery.Id);
            record.Name         = machinery.title;
            record.Description  = machinery.Description;
            record.UserAuthorID = machinery.UserAuthor;
            record.CategoryID   = machinery.Category;
            record.ChangeStatus((Record.StatusType)machinery.Status);

            record.Specifications = new List <Specification>();
            foreach (WorkLinqToSql.MachineSpecification mSP in machinery.MachineSpecifications)
            {
                record.Specifications.Add(ToSpecification(mSP.Specification));
            }

            if (machinery.MachineTags.Count() > 0)
            {
                record.Tags = new List <Tag>();
                foreach (WorkLinqToSql.MachineTag mT in machinery.MachineTags)
                {
                    record.Tags.Add(ToTag(mT.Tag));
                }
            }
            else
            {
                record.Tags = null;
            }

            if (machinery.Document.Count() > 0)
            {
                record.Files = new List <File>();
                foreach (WorkLinqToSql.Document document in machinery.Document)
                {
                    record.Files.Add(ToFile(document));
                }
            }
            else
            {
                record.Files = null;
            }


            return(record);
        }
Beispiel #5
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);
        }