public HttpResponseMessage PostCardset([FromBody] Cardset cardsetToAdd)
        {
            var userId = RequestContext.Principal.Identity.GetUserId();

            if (userId == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
            else
            {
                cardsetToAdd.UserId = userId;
            }


            ModelState.Remove("cardsetToAdd.UserId");

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            _cardsetRepo.AddCardset(cardsetToAdd);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
예제 #2
0
        public static Cardset LoadCardset(string text)
        {
            string lastLine = "";
            string thisLine = "";
            var    lines    = new StringReader(text);
            var    cardSet  = new Cardset();

            while ((thisLine = lines.ReadLine()) != null)
            {
                if (thisLine.StartsWith("===="))
                {
                    cardSet.Name = lastLine;
                }
                if (thisLine.StartsWith("----"))
                {
                    var newSection = new Section()
                    {
                        Title = lastLine,
                        Cards = new List <Card>(),
                    };
                    if (cardSet.Sections == null)
                    {
                        cardSet.Sections = new List <Section>();
                        newSection.Id    = 1;
                    }
                    else
                    {
                        newSection.Id = cardSet.Sections.Last().Id + 1;
                    }
                    cardSet.Sections.Add(newSection);
                }
                if (thisLine.Contains(':'))
                {
                    if (cardSet.Sections == null)
                    {
                        cardSet.Sections = new List <Section>();
                        cardSet.Sections.Add(new Section());
                    }

                    var newCard = new Card(thisLine);
                    cardSet.Sections.Last().Cards.Add(newCard);
                }

                lastLine = thisLine;
            }

            return(cardSet);
        }
예제 #3
0
 public void AddCardset(Cardset cardset)
 {
     _context.Cardsets.Add(cardset);
     _context.SaveChanges();
 }