Example #1
0
        public async Task <IEnumerable <NewCreativeModel> > CreateCreative(NewCreativeModel model)
        {
            var creative = await InitNewCreative(model);

            db.Creatives.Add(creative);

            db.Save();

            var res = db.Creatives.Find(c => string.Equals(c.User.UserName, model.UserName, StringComparison.CurrentCultureIgnoreCase));

            return(InitCreativesModel(res));
        }
Example #2
0
        private async Task <Creative> InitNewCreative(NewCreativeModel model)
        {
            var creative = new Creative
            {
                Name        = model.Name,
                Description = model.Description,
                Category    = await db.Categories.Get(model.CategoryId),
                Tags        = model.Tags.Select(x => new Tag {
                    Name = x.Name
                }).ToList(),
                Created  = DateTime.Now,
                Rating   = new List <Rating>(),
                Comments = new List <Comment>()
            };

            var user = await db.Users.FindUser(model.UserName);

            creative.User = user;

            return(creative);
        }
Example #3
0
        public async Task <NewCreativeModel> UpdateCreative(NewCreativeModel model)
        {
            var creative = await db.Creatives.Get(model.Id);

            creative.Name = model.Name;

            creative.Description = model.Description;

            foreach (var chapter in model.Chapters)
            {
                chapterService.AddOrUpdateChapter(chapterService.InitChapterViewModel(chapter));
            }

            var tagsToDelete = new List <Tag>();

            foreach (var tag in creative.Tags)
            {
                if (!model.Tags.Contains(tagsService.InitTagViewModel(tag), new CompareTagViewModels()))
                {
                    tagsToDelete.Add(tag);
                }
            }

            db.Tags.RemoveRange(tagsToDelete);

            foreach (var newTag in model.Tags.Where(newTag => newTag.CreativeId != creative.Id))
            {
                newTag.CreativeId = creative.Id;

                db.Tags.Add(new Tag {
                    CreativeId = newTag.CreativeId, Name = newTag.Name
                });
            }

            db.Creatives.Update(creative);

            db.Save();

            return(InitCreativeModel(creative));
        }
Example #4
0
 public async Task <IHttpActionResult> UpdateCreative(NewCreativeModel model)
 {
     return(Ok(await service.UpdateCreative(model)));
 }
Example #5
0
        public async Task <IHttpActionResult> UpdateCreative(NewCreativeModel model)
        {
            await creativeService.UpdateCreative(model);

            return(Ok(creativeService.GetAllCreatives()));
        }