Exemplo n.º 1
0
        public IHttpActionResult PutAttribute(String Attr_Name, String Attr_Value)
        {
            Models.Attribute attr = new Models.Attribute();
            attr.ATTR_ID    = Guid.NewGuid();
            attr.ATTR_Name  = Attr_Name;
            attr.ATTR_Value = Attr_Value;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Attributes.Add(attr);


            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AttributeExists(attr.ATTR_ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult New(Game gameRequest)
        {
            var selectedAttributes = gameRequest.AttributesList.Where(b => b.Checked).ToList();

            try
            {
                if (ModelState.IsValid)
                {
                    gameRequest.Attributes = new List <Models.Attribute>();
                    for (int i = 0; i < selectedAttributes.Count(); i++)
                    {
                        Models.Attribute attribute = db.Attributes.Find(selectedAttributes[i].Id);
                        gameRequest.Attributes.Add(attribute);
                    }
                    db.Games.Add(gameRequest);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(gameRequest));
            }
            catch (Exception e)
            {
                var msg = e.Message;
                return(View(gameRequest));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get Controls Data with attributes.
        /// </summary>
        /// <returns></returns>
        public List <ControlInfo> GetControls()
        {
            var controlToShow       = GetStoredControl();
            var attribute           = GetStoredControlAttributes();
            List <ControlInfo> info = new List <ControlInfo>();

            foreach (var control in controlToShow)
            {
                ControlInfo             field = new ControlInfo();
                List <Models.Attribute> item  = new List <Models.Attribute>();
                foreach (var feature in attribute)
                {
                    if (control.ControlId == feature.ControlId)
                    {
                        Models.Attribute attributeItem = new Models.Attribute();
                        attributeItem.AttributeName  = feature.AttributeName;
                        attributeItem.AttributeValue = feature.AttributeValue;
                        item.Add(attributeItem);
                    }
                }
                field.ControlId         = control.ControlId;
                field.Label             = control.Label;
                field.Type              = control.Type;
                field.IsVisible         = control.IsVisible;
                field.IsReadOnly        = control.IsReadOnly;
                field.Order             = control.Order;
                field.ControlAttributes = item.ToList();
                info.Add(field);
            }

            return(info);
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> PutAttribute(int id, Models.Attribute attribute)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != attribute.Id)
            {
                return(BadRequest());
            }

            db.Entry(attribute).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AttributeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 5
0
        public JsonpResult SaveAttribute(string appid, string compid, string attribute)
        {
            string clientid = Request.Params["clientkey"];
            var    apm      = new Tz.App.AppManager(clientid, appid);

            apm.GetComponents();
            var comp = apm.GetComponent(compid);

            Core.ComponentManager mg = new ComponentManager(comp);

            Models.Attribute att = new Models.Attribute();
            att = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.Attribute>(attribute);
            //  Core.ComponentManager mg = new ComponentManager(clientid, compid);
            var natt = new ComponentAttribute(clientid)
            {
                AttributeName = att.AttributeName,
                AttributeType = (Core.ComponentAttribute.ComoponentAttributeType)att.AttributeType,
                ClientID      = clientid,
                DefaultValue  = att.DefaultValue,
                FileExtension = att.FileExtension,
                IsAuto        = att.IsAuto,
                IsCore        = att.IsCore,
                IsNullable    = att.IsNullable,
                IsPrimaryKey  = att.IsPrimaryKey,
                IsReadOnly    = att.IsReadOnly,
                IsRequired    = att.IsRequired,
                IsSecured     = att.IsSecured,
                IsUnique      = att.IsUnique,
                LookUpID      = att.LookUpID,
                Length        = att.Length,
                RegExp        = att.RegExp
            };

            return(new JsonpResult(mg.AddAttribute(natt)));
        }
        /// <summary>
        /// /
        /// </summary>
        /// <param name="clientid"></param>
        /// <param name="componentId"></param>
        /// <param name="attribute"></param>
        /// <returns></returns>
        public JsonpResult AddAttribute(string clientid, string componentId, string attribute)
        {
            //  Tz.Net.ClientServer c = new Net.ClientServer(clientid);
            Models.Attribute att = new Models.Attribute();
            att = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.Attribute>(attribute);
            Core.ComponentManager mg = new ComponentManager(clientid, componentId);
            var natt = new ComponentAttribute(clientid)
            {
                AttributeName = att.AttributeName,
                AttributeType = (Core.ComponentAttribute.ComoponentAttributeType)att.AttributeType,
                ClientID      = clientid,
                DefaultValue  = att.DefaultValue,
                FileExtension = att.FileExtension,
                IsAuto        = att.IsAuto,
                IsCore        = att.IsCore,
                IsNullable    = att.IsNullable,
                IsPrimaryKey  = att.IsPrimaryKey,
                IsReadOnly    = att.IsReadOnly,
                IsRequired    = att.IsRequired,
                IsSecured     = att.IsSecured,
                IsUnique      = att.IsUnique,
                Length        = att.Length,
                RegExp        = att.RegExp
            };

            natt.setFieldID(att.FieldID);
            if (att.FieldID != "")
            {
                return(new JsonpResult(mg.ChangeAttribute(natt)));
            }
            else
            {
                return(new JsonpResult(mg.AddAttribute(natt)));
            }
        }
        private void WritePzVoltData(BLEPeripheral peripheral)
        {
            if (peripheral.Characteristics.ContainsKey("PiezoVoltage"))
            {
                long timestamp = peripheral.UptimeMilliseconds;
                long period    = 333;

                Models.Attribute attr = peripheral.Characteristics["PiezoVoltage"].ValueAttribute;
                for (int i = 0; i < attr.Value.Length / 2; i++)
                {
                    long   time  = timestamp - (period / (attr.Value.Length / 2) * (((attr.Value.Length / 2) - 1) - i));
                    ushort value = BitConverter.ToUInt16(attr.Value, 2 * i);

                    try
                    {
                        using (StreamWriter output = new StreamWriter(peripheral.SaveFile.Substring(0, peripheral.SaveFile.Length - 4) + "volt.csv", true))
                        {
                            output.WriteLine(time + "," + value);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        //MessageWriter.LogWrite("Error writing file. Check save location.");
                    }
                }
            }
        }
Exemplo n.º 8
0
        public ActionResult MoveDown(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var attributes = db.Attributes.Where(s => s.ProjectId == PageManager.CurrentProject.ID);

            Models.Attribute attribute = db.Attributes.Find(id);
            if (attributes == null)
            {
                return(HttpNotFound());
            }

            var desiredOrderID = attribute.OrderID + 1;
            var attributeWithDesiredOrderID = attributes.ToList().Find(s => s.OrderID == desiredOrderID);

            if (attributeWithDesiredOrderID != null)
            {
                attributeWithDesiredOrderID.OrderID = attribute.OrderID;
                db.SaveChanges();
                db.Entry(attribute).State = EntityState.Modified;
                attribute.OrderID         = desiredOrderID;
                db.SaveChanges();
            }

            return(RedirectToAction("Home", "Attributes"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,AttributeName")] Models.Attribute attribute)
        {
            if (id != attribute.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(attribute);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AttributeExists(attribute.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(attribute));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Edit(long id, [Bind("Name,Slug,IsVisible,Variations,AttributeType,AttributePosition,Id,CreateDate,CreatedBy,UpdateDate,UpdatedBy,AppTenantId")] Models.Attribute attribute)
        {
            if (id != attribute.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    attribute.UpdatedBy   = User.Identity.Name ?? "username";
                    attribute.UpdateDate  = DateTime.Now;
                    attribute.AppTenantId = tenant.AppTenantId;

                    _context.Update(attribute);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AttributeExists(attribute.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(attribute));
        }
Exemplo n.º 11
0
 private static string GenericObjectToDisplayable(object data, Models.Attribute attribute)
 {
     if (data == null)
     {
         return(string.Empty);
     }
     if (data is EntityReferenceValue)
     {
         return(((EntityReferenceValue)data).DisplayName);
     }
     else if (data is OptionSetValue)
     {
         var option = attribute.Options.FirstOrDefault(k => k.Value == ((OptionSetValue)data).Value);
         return(option?.DisplayName ?? string.Empty);
     }
     else if (data is bool)
     {
         return((bool)data ? "Yes" : "No");
     }
     else
     {
         return(attribute.IsCustomAttribute
             ? string.Empty
             : data.ToString());
     }
 }
        public ActionResult AddAttributeToRestaurant(int id, String attribute)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Restaurant restaurant = db.Restaurants.Find(id);

            if (restaurant == null)
            {
                return(HttpNotFound());
            }
            bool exist = restaurant.Attributes.Any(x => x.Type == attribute);

            if (!exist)
            {
                Models.Attribute NewAttribute = new Models.Attribute()
                {
                    Type = attribute
                };
                db.SaveChanges();
                restaurant.Attributes.Add(NewAttribute);
                db.SaveChanges();
                return(Json(new { status = "Success", message = "Success" }));
            }
            return(Json(new { status = "No", message = "No" }));
        }
Exemplo n.º 13
0
        public void CheckTableScheme_TableSchemeHasAttributeWithUnknownType_ThrowsInvalidAttributeException()
        {
            // Arrange
            string tableName     = "testTable";
            string attributeName = "testAttribute";

            string[] attributeTypes = { null, "testType" };

            // Arrange - create target
            DatabaseValidation target = new DatabaseValidation(this._dbValidationSettings);

            // Act and Assert
            foreach (string attributeType in attributeTypes)
            {
                Models.Attribute attribute = new Models.Attribute {
                    Name = attributeName, Type = attributeType
                };

                TableScheme tableScheme = new TableScheme(tableName, new List <Models.Attribute> {
                    attribute
                });

                InvalidTableAttributesException ex =
                    Assert.Throws <InvalidTableAttributesException>(() => target.CheckTableScheme(tableScheme));

                Assert.NotNull(ex.InnerException);
                Assert.AreSame(ex.InnerException.GetType(), typeof(InvalidAttributeException));
            }
        }
Exemplo n.º 14
0
        public ActionResult Attributes(AttributeGroupViewModel postAttribute)
        {
            if (ModelState.IsValid)
            {
                var form = postAttribute.Form;
                if (form.NewGroup != null)
                {
                    var group = new AttributeGroup()
                    {
                        AttributeGroupName = form.NewGroup
                    };
                    _context.AttributeGroups.Add(group);
                    _context.SaveChanges();
                }
                else if (form.SelectGroup != null && form.AttributeName != null)
                {
                    var attribute = new Models.Attribute()
                    {
                        AttributeGroupId = form.SelectGroup, Name = form.AttributeName, ValueType = form.ValueType
                    };
                    _context.Attributes.Add(attribute);
                    _context.SaveChanges();
                }
            }

            return(RedirectToAction(nameof(AttributesController.Attributes), "Attributes"));
        }
 public ActionResult DeleteConfirmed(Guid id)
 {
     Models.Attribute attribute = db.Attributes.Find(id);
     db.Attributes.Remove(attribute);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 16
0
        public ActionResult Delete(string EleCode)
        {
            var attributeContext = new DBModelEntities();
            IList <Models.Attribute> attributes = attributeContext.Attributes.ToList();

            //Models.Attribute.AttributesList = db.Attributes.ToList();
            Models.Attribute attribute = db.Attributes.Find(Convert.ToInt32(EleCode));

            db.Attributes.Remove(attribute);
            db.SaveChanges();

            /*  foreach (AttributesViewModel i in AttributesViewModel.AttributesList)
             * {
             *    if (i.ElementCode == EleCode)
             *    {
             *        AttributesViewModel.AttributesList.Remove(i);
             *        return Json(new
             *        {
             *            aaData = AttributesViewModel.AttributesList.Select(x => new[] { x.ElementCode, x.ElementName, x.AttributeCode, x.AttributeName, x.DateSet.ToString(), x.CreatedBy })
             *        }, JsonRequestBehavior.AllowGet);
             *    }
             * }
             */
            return(Json(new
            {
                //aaData = AttributesViewModel.AttributesList.Select(x => new[] { x.ElementCode, x.ElementName, x.AttributeCode, x.AttributeName, x.DateSet.ToString(), x.CreatedBy })
                aaData = attributes.Select(x => new[] { x.Element.Code.ToString(), x.Element.Name, x.Code.ToString(), x.Name, x.CreatedOn.ToString(), x.CreatedBy })
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 17
0
        public async Task <Models.Attribute> Create(Models.Attribute attribute)
        {
            attribute.AttrId = Guid.NewGuid();
            _context.Attributes.Add(attribute);
            await _context.SaveChangesAsync();

            return(attribute);
        }
 public ActionResult DeleteConfirmedATTR(Guid id, Guid?idAttr)
 {
     Models.Employee  employee  = db.Employees.Find(id);
     Models.Attribute attribute = db.Attributes.Find(idAttr);
     employee.Attributes.Remove(attribute);
     db.Attributes.Remove(attribute);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 19
0
        public async Task <IActionResult> CreateAttribute(string name)
        {
            Models.Attribute attribute = new Models.Attribute()
            {
                Name = name
            };
            await _attributeService.AddAttribute(attribute);

            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ATTR_ID,ATTR_Name,ATTR_Value")] Models.Attribute attribute)
 {
     if (ModelState.IsValid)
     {
         db.Entry(attribute).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(attribute));
 }
Exemplo n.º 21
0
        public async Task <IActionResult> Create([Bind("ID,AttributeName")] Models.Attribute attribute)
        {
            if (ModelState.IsValid)
            {
                _context.Add(attribute);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(attribute));
        }
Exemplo n.º 22
0
        public async Task <IHttpActionResult> GetAttribute(int id)
        {
            Models.Attribute attribute = await db.Attribute.FindAsync(id);

            if (attribute == null)
            {
                return(NotFound());
            }

            return(Ok(attribute));
        }
Exemplo n.º 23
0
        private void AddColumn(Models.Attribute column)
        {
            Binding dataBinding = new Binding();

            dataBinding.Path = new PropertyPath($"Values[{column.LogicalName}]");
            dataBinding.Mode = BindingMode.OneWay;
            this.DataMainGrid.Columns.Add(new DataGridTextColumn()
            {
                Header = column.DisplayName, Binding = dataBinding, IsReadOnly = true
            });
        }
Exemplo n.º 24
0
        // Attribute Mapping
        public static AttributeDto MapToAttributeDto(Models.Attribute attribute)
        {
            var attributeDto = new AttributeDto
            {
                AttrId             = attribute.AttrId,
                AttrName           = attribute.AttrName,
                AttrValue          = attribute.AttrValue,
                EmployeeAttributes = new Collection <EmployeeAttributeDto>()         // at this point we are ok with new Collection, lateer need to modify
            };

            return(attributeDto);
        }
        public ActionResult Create([Bind(Include = "ATTR_ID,ATTR_Name,ATTR_Value")] Models.Attribute attribute)
        {
            if (ModelState.IsValid)
            {
                attribute.ATTR_ID = Guid.NewGuid();
                db.Attributes.Add(attribute);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(attribute));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Add an attribute object to the remote database.
        /// </summary>
        /// <param name="attribute">The attribute to be added</param>
        /// <returns></returns>
        public async Task PostAttributeAsync(Models.Attribute attribute)
        {
            var client = new HttpClient();

            var         json    = JsonConvert.SerializeObject(attribute);
            HttpContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            content.Headers.Add("ZUMO-API-VERSION", "2.0.0");

            var response = await client.PostAsync(Constants.BaseApiAddress + "api/attribute", content);
        }
Exemplo n.º 27
0
        // GET: CmsCore/Attributes/Create
        public IActionResult Create()
        {
            var attribute = new Models.Attribute();

            attribute.CreatedBy   = User.Identity.Name ?? "username";
            attribute.CreateDate  = DateTime.Now;
            attribute.UpdatedBy   = User.Identity.Name ?? "username";
            attribute.UpdateDate  = DateTime.Now;
            attribute.AppTenantId = tenant.AppTenantId;

            return(View(attribute));
        }
Exemplo n.º 28
0
        public async Task <IHttpActionResult> PostAttribute(Models.Attribute attribute)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Attribute.Add(attribute);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = attribute.Id }, attribute));
        }
Exemplo n.º 29
0
        public static Models.Attribute MapToAttribute(AttributeDto attributeDto)
        {
            var attribute = new Models.Attribute
            {
                AttrId             = attributeDto.AttrId,
                AttrName           = attributeDto.AttrName,
                AttrValue          = attributeDto.AttrValue,
                EmployeeAttributes = new Collection <EmployeeAttribute>()
            };

            return(attribute);
        }
Exemplo n.º 30
0
        public async Task <IActionResult> CreatedTable(string tablename, int fieldsnumber)
        {
            Models.TableModel tableModel = new Models.TableModel
            {
                Name = tablename,
                NumberOfAttributes = fieldsnumber
            };

            List <String>           valuesToInsert = new List <String>();
            List <Models.Attribute> listValues     = new List <Models.Attribute>();

            for (int i = 0; i < fieldsnumber; i++)
            {
                var field = new Models.Attribute
                {
                    Name = Request.Form[String.Format("{0} {1}", "fieldName", i)],
                    Type = Request.Form[String.Format("{0} {1}", "fieldType", i)]
                };
                listValues.Add(field);


                valuesToInsert.Add(Request.Form[field.Name]);
            }
            tableModel.Attributes = listValues;


            WebServiceSoapClient.EndpointConfiguration endpointConfiguration = WebServiceSoapClient.EndpointConfiguration.WebServiceSoap;
            var client = new WebServiceSoapClient(endpointConfiguration);

            if (valuesToInsert[0] != null)
            {
                var arrString = new ArrayOfString();
                arrString.AddRange(valuesToInsert);
                var tmp = await client.AddToTableInBDAsync(tableModel.ConvertToServiceModel(), arrString);

                if (tmp.Body.AddToTableInBDResult)
                {
                    return(View(tableModel));
                }
                return(View("Error"));
            }
            else
            {
                var tmp = await client.CreateTableInBDAsync(tableModel.ConvertToServiceModel());

                if (tmp.Body.CreateTableInBDResult)
                {
                    return(View(tableModel));
                }
                return(View("Error"));
            }
        }
Exemplo n.º 31
0
        //
        // GET: /Form/Details/5
        public ViewResult Details(int id)
        {
            Form form = (Form)RavenSession.Query<Form>().Where(f => f.Id == id).First();

            // how can i handle the issue where "attributes" property
            // was added at a later date, but earlier docs do not have
            // it? so when you try to access the doc, it throughs a
            // System.NullException error

            if (form.Attributes == null) {
                form.Attributes = new List<Models.Attribute>();
                Models.Attribute blank = new Models.Attribute();
                blank.Name = "No attributes available";
                blank.Value = "-1";
                form.Attributes.Add(blank);
            }

            return View(form);
        }
        public ActionResult Enter(DataHolder d)
        {
            //this puts each line onto a string list, and also trims each line
            string[] splitCharacters = new string[] { "\r\n" };
            List<string> eachLine = d.DataString.Split(splitCharacters, StringSplitOptions.RemoveEmptyEntries).ToList();
            eachLine = eachLine.Select(i => i.Trim()).ToList();

            //gets @relation name
            string datasetName = eachLine.ElementAt(0).Substring(9);

            //add a dataset instance
            DataSet dataset = new DataSet { Name = datasetName };
            db.DataSets.Add(dataset);
            db.SaveChanges();

            //gets each attribute name
            List<string> attributeNames = new List<string>();
            foreach(var line in eachLine.Where(i=>i.Length>=10 && i.Substring(0,10) == "@attribute"))
            {
                attributeNames.Add(line.Split(' ')[1]);
            }

            int data = eachLine.IndexOf("@data");
            foreach (var line in eachLine.Skip(data+1))
            {
                string instanceClass = line.Split(',')[attributeNames.Count - 1];
                Instance instance = new Instance { Class = instanceClass, DataSetID = dataset.ID };
                db.Instances.Add(instance);
                db.SaveChanges();
                foreach(var attributeName in attributeNames.TakeWhile(i=>i != attributeNames.Last()))
                {
                    Models.Attribute attrObj = new Models.Attribute { AttributeName = attributeName, AttributeValue = line.Split(',')[attributeNames.IndexOf(attributeName)], InstanceID = instance.ID };
                    db.Attributes.Add(attrObj);
                    db.SaveChanges();
                }
            }
            return RedirectToAction("Index");
        }
Exemplo n.º 33
0
 public void AddAttribute(string name, string value)
 {
     var currAtt = new Models.Attribute(name, value);
     this.attributes.Add(currAtt);
 }