コード例 #1
0
        public Guid InsertPointAttribute(PointAttributeModel pointAttribute)
        {
            if (pointAttribute == null)
            {
                throw new NullReferenceException("pointAttribute");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                POINTS_ATTRIBUTES novo = new POINTS_ATTRIBUTES
                {
                    ID           = (pointAttribute.Id == null || pointAttribute.Id == Guid.Empty ? Guid.NewGuid() : pointAttribute.Id),
                    POINT        = data.POINT.Single(x => x.ID.Equals(pointAttribute.Point.Id)),
                    KEYPAIR      = pointAttribute.KeyPair,
                    VALUE_BOOL   = pointAttribute.Value_bool,
                    VALUE_STRING = pointAttribute.Value_string,
                    VALUE_DATE   = pointAttribute.Value_Date,
                    VALUE_NUMBER = pointAttribute.Value_number,
                    VALUE_TYPE   = pointAttribute.Value_Type,
                    IS_ACTIVE    = pointAttribute.IsActive
                };

                data.POINTS_ATTRIBUTES.AddObject(novo);
                data.SaveChanges();

                return(novo.ID);
            }
        }
コード例 #2
0
        public void DeletePointAttribute(PointAttributeModel pointAttributeModel)
        {
            if (pointAttributeModel == null)
            {
                throw new ArgumentNullException("pointAttributeModel");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                try
                {
                    POINTS_ATTRIBUTES current = data.POINTS_ATTRIBUTES.Single(p => p.ID == pointAttributeModel.Id);

                    if (current != null)
                    {
                        data.POINTS_ATTRIBUTES.DeleteObject(current);
                        data.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        throw new Exception(e.InnerException.Message);
                    }
                    throw;
                }
            }
        }
コード例 #3
0
        public void UpdateAttribute(PointAttributeModel pointAttributeModel)
        {
            if (pointAttributeModel == null)
            {
                throw new ArgumentNullException("pointAttributeModel");
            }

            using (AppTourEntities data = new AppTourEntities())
            {
                try
                {
                    POINTS_ATTRIBUTES current = data.POINTS_ATTRIBUTES.Single(p => p.ID == pointAttributeModel.Id);

                    if (current != null)
                    {
                        current.KEYPAIR      = pointAttributeModel.KeyPair;
                        current.VALUE_BOOL   = pointAttributeModel.Value_bool;
                        current.VALUE_DATE   = pointAttributeModel.Value_Date;
                        current.VALUE_NUMBER = pointAttributeModel.Value_number;
                        current.VALUE_STRING = pointAttributeModel.Value_string;
                        current.VALUE_TYPE   = pointAttributeModel.Value_Type;
                        current.IS_ACTIVE    = pointAttributeModel.IsActive;

                        data.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        throw new Exception(e.InnerException.Message);
                    }
                    throw;
                }
            }
        }
コード例 #4
0
        /* POC
         #region + GetActivePoints(Guid Topic)
         * public IList<PointModel> GetActivePoints(Guid TopicId)
         * {
         *  using (AppTourEntities data = new AppTourEntities())
         *  {
         *      var points = this.GetPoints(data).ToList();
         *
         *      Parallel.ForEach(points, x =>
         *      {
         *          x.Topics = new TopicRepository().GetTopicsForPoint(x.Id);
         *          x.Attributes = new PointAttributeRepository().GetAttributeForPoints(x.Id);
         *      });
         *
         *      return points.ToList().Where(x => x.Topics.All(y => y.Id.Equals(TopicId))).ToList();
         *  }
         * }
         #endregion
         */

        #region + UpdatePoint(PointModel point)
        public void UpdatePoint(PointModel point)
        {
            using (AppTourEntities data = new AppTourEntities())
            {
                POINT current = data.POINT.Include("POINT_TOPIC").Single(x => point.Id == x.ID);

                if (current != null)
                {
                    try
                    {
                        current.NAME         = point.Name;
                        current.ADDRESS      = point.Address;
                        current.POSTAL_CODE  = point.PostalCode;
                        current.CITY         = data.CITY.Where(x => x.ID == point.City.Id).FirstOrDefault();
                        current.COORDENATE   = point.Coordenate;
                        current.PHONE_NUMBER = point.PhoneNumber;
                        current.URL          = point.URL;
                        current.SOURCE_URL   = point.SourceURL;
                        current.IS_ACTIVE    = point.IsActive;

                        if (point.Topics != null && point.Topics.Count() > 0)
                        {
                            current.POINT_TOPIC.ToList().ForEach(x =>
                            {
                                data.POINT_TOPIC.DeleteObject(x);
                            });
                            // Adicionar Topicos
                            foreach (TopicModel item in point.Topics)
                            {
                                POINT_TOPIC pt = new POINT_TOPIC
                                {
                                    ID    = Guid.NewGuid(),
                                    TOPIC = data.TOPIC.Single(x => x.ID.Equals(item.Id)),
                                    POINT = current
                                };
                                current.POINT_TOPIC.Add(pt);
                            }
                        }


                        // Atributos
                        if (point.Attributes != null && point.Attributes.Count > 0)
                        {
                            foreach (PointAttributeModel attribute in point.Attributes)
                            {
                                POINTS_ATTRIBUTES attr;
                                if (attribute.Id != Guid.Empty)
                                {
                                    attr              = current.POINTS_ATTRIBUTES.Where(x => x.ID == attribute.Id).Single();
                                    attr.POINT        = data.POINT.Single(x => x.ID == attribute.Point.Id);
                                    attr.KEYPAIR      = attribute.KeyPair;
                                    attr.VALUE_BOOL   = attribute.Value_bool;
                                    attr.VALUE_STRING = attribute.Value_string;
                                    attr.VALUE_NUMBER = Decimal.Parse(attribute.Value_number.ToString());
                                    attr.VALUE_DATE   = attribute.Value_Date;
                                    attr.VALUE_TYPE   = attribute.Value_Type;
                                    attr.IS_ACTIVE    = attribute.IsActive;
                                }
                                else
                                {
                                    attr = new POINTS_ATTRIBUTES
                                    {
                                        ID           = Guid.NewGuid(),
                                        POINT        = data.POINT.Single(x => x.ID == attribute.Point.Id),
                                        KEYPAIR      = attribute.KeyPair,
                                        VALUE_BOOL   = attribute.Value_bool,
                                        VALUE_STRING = attribute.Value_string,
                                        VALUE_NUMBER = Decimal.Parse(attribute.Value_number.ToString()),
                                        VALUE_DATE   = attribute.Value_Date,
                                        VALUE_TYPE   = attribute.Value_Type,
                                        IS_ACTIVE    = attribute.IsActive
                                    };
                                }
                                current.POINTS_ATTRIBUTES.Add(attr);
                            }
                        }
                        data.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            throw new Exception(e.InnerException.Message);
                        }
                        throw;
                    }
                }
            }
        }