Exemplo n.º 1
0
        public async Task <ActionResult <UserColorModel> > PostUserColor(UserColorModel userColorModel)
        {
            UserColor userColor = userColorModel.ToEntity();

            _context.UserColors.Add(userColor);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserColor", new { id = userColor.Id }, userColor));
        }
Exemplo n.º 2
0
 public static UserColor ToEntity(this UserColorModel model)
 {
     return(new UserColor
     {
         Name = model.Name,
         Alpha = model.Alpha,
         Red = model.Red,
         Green = model.Green,
         Blue = model.Blue,
     });
 }
Exemplo n.º 3
0
 private async Task DeleteColor(UserColorModel color)
 {
     if (color.Id == -1)
     {
         bsc_list.RemoveCurrent();
     }
     else
     {
         await api.DeleteAsync <UserColorModel>(API_URL + "/api/usercolors/" + color.Id, async (deleted) =>
         {
             await GetColors();
         });
     }
 }
Exemplo n.º 4
0
        private void ItemChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        {
            if (getting)
            {
                return;
            }
            int            id      = e.NewIndex;
            UserColorModel current = ((List <UserColorModel>)bsc_list.DataSource)[id];

            if (!editedIds.Contains(current.Id))
            {
                editedIds.Add(current.Id);
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutUserColor(int id, UserColorModel userColorModel)
        {
            if (id != userColorModel.Id)
            {
                return(BadRequest());
            }

            UserColor color = _context.UserColors.Find(id);

            if (!UserColorExists(id))
            {
                return(BadRequest());
            }

            color.Name  = userColorModel.Name;
            color.Red   = userColorModel.Red;
            color.Green = userColorModel.Green;
            color.Blue  = userColorModel.Blue;
            color.Alpha = userColorModel.Alpha;

            _context.Entry(color).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemplo n.º 6
0
        private void AddHex(string name, string hex)
        {
            hex = hex.TrimStart('#');
            if (hex.Length == 6)
            {
                hex = "FF" + hex;
            }

            Color c = Color.FromArgb(Int32.Parse(hex, System.Globalization.NumberStyles.HexNumber));

            UserColorModel color = new UserColorModel
            {
                Id    = -1,
                Name  = name,
                Alpha = c.A,
                Red   = c.R,
                Green = c.G,
                Blue  = c.B
            };

            Colors.Add(color);
            AddDataBindings();
        }
Exemplo n.º 7
0
 private async Task PutColor(UserColorModel color)
 {
     await api.PutAsync <UserColorModel, UserColorModel>(API_URL + "/api/usercolors/" + color.Id, color);
 }
Exemplo n.º 8
0
 private async Task PostColor(UserColorModel color)
 {
     await api.PostAsync <UserColorModel, UserColorModel>(API_URL + "/api/usercolors", color);
 }