Beispiel #1
0
 public void Insert(MemeCoordinates memeCoords)
 {
     using (var context = new Context())
     {
         context.MemeCoordinates.Add(memeCoords);
         context.SaveChanges();
     }
 }
        public ActionResult Create(Template template, string[] textData, string dataURL)
        {
            int    templateId = template.Id;
            string title      = template.Title;

            byte[] bytes = Convert.FromBase64String(dataURL.Split(',')[1]);

            try
            {
                template = _templateRepo.GetById(templateId);
                User currentUser = _userRepo.GetByUsername(User.Identity.Name);
                List <MemeCoordinates> memeCoords = new List <MemeCoordinates>();

                Meme meme = new Meme()
                {
                    Title      = title,
                    Url        = template.Url,
                    CreatorId  = currentUser.Id,
                    ImageBytes = bytes
                };
                int memeId = _memeRepo.AddMeme(meme);
                for (int i = 0; i < template.Coordinates.Count; i++)
                {
                    MemeCoordinates mCoord = new MemeCoordinates()
                    {
                        X      = template.Coordinates[i].X,
                        Y      = template.Coordinates[i].Y,
                        Text   = textData[i],
                        MemeId = memeId
                    };
                    _memeCoordsRepo.Insert(mCoord);
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
            }

            return(RedirectToAction("Create", new { id = templateId }));
        }