Esempio n. 1
0
 public void EditDocument(CreateModelDto document)
 {
     if (document.IsCreate)
     {
         CreateDocument(document);
     }
     else
     {
         UpdateDocument(document);
     }
 }
Esempio n. 2
0
 public void UpdateDocument(CreateModelDto document)
 {
     if (document.File != null)
     {
         UploadImageForArticle(document.Id, document.File, document.IsDiary);
     }
     if (document.IsDiary)
     {
         var entity = db.Diary.Where(c => c.Id == document.Id).AsQueryable().FirstOrDefault();
         if (entity != null)
         {
             entity.Name            = document.Name;
             entity.Body            = document.Body;
             entity.AlbumYear       = document.AlbumYear.Value;
             entity.CatalogueNumber = document.CatalogueNumber;
             entity.Genre           = document.Genre;
             entity.ReleaseYear     = document.ReleaseYear.Value;
             entity.Label           = document.Label;
             if (entity.IsPublished != document.IsPublished)
             {
                 entity.IsPublished = document.IsPublished;
                 entity.DateCreated = DateTime.Now;
             }
         }
         db.Entry(entity).State = EntityState.Modified;
     }
     else
     {
         var entity = db.Articles.Where(c => c.Id == document.Id).AsQueryable().FirstOrDefault();
         if (entity != null)
         {
             entity.Name             = document.Name;
             entity.Body             = document.Body;
             entity.Prelude          = document.Prelude;
             entity.DateEdited       = DateTime.Now;
             entity.CategoryId       = articleHelper.GetCategoryByName(document.CategoryId).Id;
             entity.SubCategoryId    = articleHelper.GetSubCategoryByName(document.SubCategoryId).Id;
             entity.Series           = articleHelper.GetSeriesByName(document.Series).Id;
             entity.IndexDescription = document.IndexDescription;
             if (entity.IsPublished != document.IsPublished)
             {
                 entity.IsPublished = document.IsPublished;
                 entity.DateCreated = DateTime.Now;
             }
         }
         db.Entry(entity).State = EntityState.Modified;
     }
     db.SaveChanges();
 }
        // Models
        public async Task <ActionResult <CreateModelDto> > CreateVehicleModel(CreateModelDto newVehicleModel)
        {
            var vehicleModel = await(
                from model in _context.VehicleModels
                join make in _context.VehicleMakes on model.MakeId equals make.Id
                select new CreateModelDto {
                MakeId = make.Id, Name = model.Name, Abrv = model.Abrv
            }
                ).SingleOrDefaultAsync();
            var newModelEntity = Mapping.Mapper.Map <VehicleModel>(newVehicleModel);

            _context.VehicleModels.Add(newModelEntity);
            await _context.SaveChangesAsync();

            return(newVehicleModel);
        }
Esempio n. 4
0
        public void CreateDocument(CreateModelDto document)
        {
            var documentIdentifier = Guid.NewGuid();

            if (document.File != null)
            {
                UploadImageForArticle(documentIdentifier, document.File, document.IsDiary);
            }
            if (document.IsDiary)
            {
                var diaryObject = new Diary {
                    Id              = documentIdentifier,
                    Name            = document.Name.Replace("'", "`"), //for search to jquery not escape quotes
                    Body            = document.Body,
                    DateCreated     = DateTime.Now,
                    Label           = document.Label,
                    ReleaseYear     = Convert.ToInt32(document.ReleaseYear),
                    AlbumYear       = Convert.ToInt32(document.AlbumYear),
                    Genre           = document.Genre,
                    CatalogueNumber = document.CatalogueNumber,
                    IsPublished     = document.IsPublished,
                    UserId          = userHelper.GetCurrentLoggedUserId()
                };
                db.Diary.Add(diaryObject);
            }
            else
            {
                var articleObject = new Models.Articles {
                    Id               = documentIdentifier,
                    Name             = document.Name.Replace("'", "`"), //for search to jquery not escape quotes
                    IndexDescription = document.IndexDescription,
                    Prelude          = document.Prelude,
                    Body             = document.Body,
                    CategoryId       = articleHelper.GetCategoryByName(document.CategoryId).Id,
                    SubCategoryId    = articleHelper.GetSubCategoryByName(document.SubCategoryId).Id,
                    Series           = articleHelper.GetSeriesByName(document.Series).Id,
                    DateCreated      = DateTime.Now,
                    DateEdited       = DateTime.Now,
                    IsPublished      = document.IsPublished,
                    UserId           = userHelper.GetCurrentLoggedUserId()
                };
                db.Articles.Add(articleObject);
            }
            db.SaveChanges();
        }
Esempio n. 5
0
        public ActionResult Edit(CreateModelDto document)
        {
            if (document.File != null)
            {
                var validImageTypes = new[] {
                    "image/gif",
                    "image/jpeg",
                    "image/pjpeg",
                    "image/png"
                };
                if (!validImageTypes.Contains(document.File.ContentType))
                {
                    ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
                }
            }
            documentService.EditDocument(document);
            var redirectUrl = new UrlHelper(Request.RequestContext).Action("Details", "Articles",
                                                                           new { id = document.Name, isDiary = document.IsDiary });

            return(Json(new { Url = redirectUrl }));
        }
Esempio n. 6
0
        public CreateModelDto GetDocumentForEdit(Guid id, bool isDiary)
        {
            var document = new CreateModelDto();

            if (isDiary)
            {
                var diary = db.Diary.Find(id);
                document.Id              = diary.Id;
                document.Name            = diary.Name;
                document.Body            = diary.Body;
                document.IsDiary         = true;
                document.AlbumYear       = diary.AlbumYear;
                document.ReleaseYear     = diary.ReleaseYear;
                document.DateCreated     = diary.DateCreated;
                document.Genre           = diary.Genre;
                document.Label           = diary.Label;
                document.IsPublished     = diary.IsPublished;
                document.CatalogueNumber = diary.CatalogueNumber;
                document.UserId          = userHelper.GetUserById(diary.UserId).UserName;
            }
            else
            {
                var article = db.Articles.Find(id);
                document.Id               = article.Id;
                document.Name             = article.Name;
                document.Body             = article.Body;
                document.IsDiary          = false;
                document.DateCreated      = article.DateCreated;
                document.IsPublished      = article.IsPublished;
                document.UserId           = userHelper.GetUserById(article.UserId).UserName;
                document.Prelude          = article.Prelude;
                document.IndexDescription = article.IndexDescription;
                document.DateEdited       = article.DateEdited;
                document.CategoryId       = articleHelper.GetCategoryById(article.CategoryId).Name;
                document.SubCategoryId    = articleHelper.GetSubCategoryById(article.SubCategoryId).Name;
                document.Series           = articleHelper.GetSeriesById(article.Series).Name;
            }
            return(document);
        }