Exemplo n.º 1
0
        public static async Task<Behavior> Insert(Behavior data)
        {
            var ctx = ModelContext.GetInstance();

            ctx.behaviors.Add(toRaw(data));

            await ctx.SaveChangesAsync();

            return (Behavior)ctx.behaviors.OrderByDescending(x => x.id).FirstOrDefault();
        }
Exemplo n.º 2
0
        public static async Task<Behavior> Update(Behavior data)
        {
            var ctx = ModelContext.GetNewInstance();

            var raw = toRaw(data);
            ctx.behaviors.Attach(raw);
            System.Data.Entity.Infrastructure.DbEntityEntry<Database.behavior> entry = ctx.Entry(raw);
            entry.State = System.Data.Entity.EntityState.Modified;

            await ctx.SaveChangesAsync();

            return Get((int)data.Id, data.UserId);
        }
Exemplo n.º 3
0
        public static Database.behavior toRaw(Behavior data)
        {
            var raw = new Database.behavior()
            {
                name = data.Name,
                lightAuto = data.LightAuto,
                waterAuto = data.WaterAuto,
                lightStartHour = data.LightStartHour,
                lightStopHour = data.LightStopHour,
                waterHumLevel = data.WaterHumLevel,
                user_id = data.UserId, 
            };

            if (data.Id != null)
            {
                raw.id = (int)data.Id;
            }

            return raw;
        }