// PUT api/Limits/5
        public async Task<IHttpActionResult> PutLimitModel(int id, LimitModel limitmodel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            var limit = db.Limits.Find(id);
            await db.Entry(limit).Collection(i => i.Tags).LoadAsync();

            if (limit.UserId != User.Identity.GetUserId())
            {
                return BadRequest();
            }

            var tagIds = limitmodel.Tags.Select(i => i.Id);
            var currentTagIds = limit.Tags.Select(i => i.Id);
            var toAdd = tagIds.Where(i => !currentTagIds.Contains(i));

            limit.Tags.RemoveAll(i => !tagIds.Contains(i.Id));
            limit.Tags.AddRange(db.Tags.Where(i => toAdd.Contains(i.Id)).ToList());
            limit.Name = limitmodel.Name;
            limit.To = limitmodel.To;
            limit.From = limitmodel.From;
            limit.Amount = limitmodel.Amount;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
        public async Task<IHttpActionResult> PostLimitModel(LimitModel limitmodel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var tagIds = limitmodel.Tags.Select(i => i.Id);

            limitmodel.UserId = User.Identity.GetUserId();
            limitmodel.Tags = await db.Tags.Where(i => tagIds.Contains(i.Id)).ToListAsync();

            db.Limits.Add(limitmodel);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = limitmodel.Id }, limitmodel);
        }