Example #1
0
 public DataAttributeManagerModel(DataAttributeModel dataAttributeModel)
 {
     DataAttributeModel = dataAttributeModel;
     dataContainerManager.DataAttributeRepo.Get().ToList().ForEach(da => DataAttributeStructs.Add(new DataAttributeStruct() { Id = da.Id, Name = da.Name, ShortName = da.ShortName, Description = da.Description, DataType = da.DataType.Name, Unit = da.Unit.Name, InUse = inUse(da), FormalDescriptions = getFormalDescriptions(da) }));
 }
Example #2
0
        public ActionResult editAttribute(DataAttributeModel Model)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Manage Data Attributes", this.Session.GetTenant());
            DataContainerManager dataAttributeManager = new DataContainerManager();
            IList<DataAttribute> DataAttributeList = dataAttributeManager.DataAttributeRepo.Get();
            long tempUnitId = Convert.ToInt64(Model.Unit.Id);
            long tempDataTypeId = Convert.ToInt64(Model.DataType.Id);

            Model.Id = Model.Id;
            Model.ShortName = cutSpaces(Model.ShortName);
            Model.Name = cutSpaces(Model.Name);
            Model.Description = cutSpaces(Model.Description);

            //if (Model.DomainConstraints.Count > 0)
            //{
            //    if (Model.DomainConstraints. != null && Model.DomainItems.Count > 0)
            //    {
            //        Model.DomainConstraints.FirstOrDefault().DomainItems = clearEmptyItems(Model.DomainItems);
            //    }
            //}

            if (Model.Name == "" | Model.Name == null)
            {
                Session["nameMsg"] = "invalid Name";
                Session["Window"] = true;
                return View("AttributeManager", new DataAttributeManagerModel(Model));
            }
            else
            {
                bool nameNotExist = DataAttributeList.Where(p => p.Name.ToLower().Equals(Model.Name.ToLower())).Count().Equals(0);

                if (Model.Id == 0)
                {
                    if (nameNotExist)
                    {
                        UnitManager UM = new UnitManager();
                        Unit unit = new Unit();
                        DataTypeManager DTM = new DataTypeManager();
                        DataType dataType = new DataType();
                        DataContainerManager DAM = new DataContainerManager();

                        DataAttribute temp = new DataAttribute();

                        if(UM.Repo.Get(tempUnitId)!= null)
                            unit = UM.Repo.Get(tempUnitId);
                        else
                            unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault();

                        if (DTM.Repo.Get(tempDataTypeId) != null)
                            dataType = DTM.Repo.Get(tempDataTypeId);
                        else
                            dataType = DTM.Repo.Get().ToList().FirstOrDefault();

                        temp = DAM.CreateDataAttribute(Model.ShortName, Model.Name, Model.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null);

                        #region store constraint

                        if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min !=null || Model.RangeConstraints.FirstOrDefault().Max !=null)
                            && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0 ))
                            temp = storeConstraint(Model.RangeConstraints.First(), temp);

                        if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase))
                            temp = storeConstraint(Model.PatternConstraints.First(), temp);

                        if (Model.DomainConstraints.Count > 0)
                        {
                            foreach (DomainConstraintModel d in Model.DomainConstraints)
                            {
                                temp = storeConstraint(d, temp);
                            }
                        }

                        #endregion

                        temp = DAM.UpdateDataAttribute(temp);
                    }
                    else
                    {
                        Session["nameMsg"] = "Name already exist";
                        Session["Window"] = true;
                        return View("AttributeManager", new DataAttributeManagerModel(Model));
                    }
                }
                else
                {
                    if (nameNotExist || DataAttributeList.Where(p => p.Name.Equals(Model.Name)).ToList().First().Id == Model.Id)
                    {
                        DataAttribute dataAttribute = DataAttributeList.Where(p => p.Id.Equals(Model.Id)).ToList().First();
                        if (!attributeInUse(dataAttribute))
                        {
                            DataContainerManager DAM = new DataContainerManager();
                            dataAttribute.Name = cutSpaces(Model.Name);
                            dataAttribute.ShortName = Model.ShortName;
                            dataAttribute.Description = Model.Description;
                            UnitManager UM = new UnitManager();

                            if (UM.Repo.Get(tempUnitId) != null)
                                dataAttribute.Unit = UM.Repo.Get(tempUnitId);
                            else
                                dataAttribute.Unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault();

                            DataTypeManager DTM = new DataTypeManager();

                            if (DTM.Repo.Get(tempDataTypeId) != null)
                                dataAttribute.DataType = DTM.Repo.Get(tempDataTypeId);
                            else
                                dataAttribute.DataType = DTM.Repo.Get().ToList().FirstOrDefault();

                            #region store constraint

                            if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min != null || Model.RangeConstraints.FirstOrDefault().Max != null)
                                && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0))
                                dataAttribute = storeConstraint(Model.RangeConstraints.First(), dataAttribute);
                            else
                                dataAttribute = deletConstraint(Model.RangeConstraints.First().Id, dataAttribute);

                            if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase))
                                dataAttribute = storeConstraint(Model.PatternConstraints.First(), dataAttribute);
                            else
                                dataAttribute = deletConstraint(Model.PatternConstraints.First().Id, dataAttribute);

                            if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.DomainConstraints.FirstOrDefault().Terms))
                                dataAttribute = storeConstraint(Model.DomainConstraints.First(), dataAttribute);
                            else
                                dataAttribute = deletConstraint(Model.DomainConstraints.First().Id, dataAttribute);

                            #endregion
                            DAM.UpdateDataAttribute(dataAttribute);
                        }
                    }
                    else
                    {
                        Session["nameMsg"] = "Name already exist";
                        Session["Window"] = true;
                        return View("AttributeManager", new DataAttributeManagerModel(Model));
                    }
                }
            }

            Session["Window"] = false;
            return RedirectToAction("AttributeManager");
        }
Example #3
0
 public DataAttributeManagerModel(long dataAttributeId, bool showConstraints = false)
 {
     DataAttributeModel = new DataAttributeModel(dataContainerManager.DataAttributeRepo.Get(dataAttributeId), showConstraints);
     dataContainerManager.DataAttributeRepo.Get().ToList().ForEach(da => DataAttributeStructs.Add(new DataAttributeStruct() { Id = da.Id, Name = da.Name, ShortName = da.ShortName, Description = da.Description, DataType = da.DataType.Name, Unit = da.Unit.Name, InUse = inUse(da), FormalDescriptions = getFormalDescriptions(da) }));
 }