Exemple #1
0
 public async Task <IActionResult> Create(CreateHeritageObjectViewModel model)
 {
     ViewBag.Buildings = _manager.BuildingRepository.GetAll();
     if (ModelState.IsValid)
     {
         string fileName = null;
         if (model.Image != null)
         {
             fileName = await UploadFile(model.Image);
         }
         HeritageObject heritageObject = new HeritageObject
         {
             Type      = model.Type,
             Image     = fileName,
             ShortDesc = model.ShortDesc, Desc = model.Desc,
             Condition = model.Condition,
             //BuildingId = model.Id,
             Building = _manager.BuildingRepository.Get(model.BuildingId)
         };
         _manager.HeritageObjectRepository.Save(heritageObject);
         //return Redirect("/HeritageObject/Index");
         //return Redirect("/admin/building");
         return(Redirect("/admin/heritageobject"));
     }
     return(View(model));
 }
Exemple #2
0
        public async Task <IActionResult> Edit(EditHeritageObjectViewModel model)
        {
            ViewBag.Buildings = _manager.BuildingRepository.GetAll();
            if (ModelState.IsValid)
            {
                HeritageObject heritageObject = _manager.HeritageObjectRepository.Get(model.Id);
                if (heritageObject != null)
                {
                    if (model.Image != null)
                    {
                        if (heritageObject.Image != null)
                        {
                            DeleteFile(heritageObject.Image);
                        }
                        heritageObject.Image = await UploadFile(model.Image);
                    }

                    heritageObject.Type       = model.Type;
                    heritageObject.Condition  = model.Condition;
                    heritageObject.ShortDesc  = model.ShortDesc;
                    heritageObject.Desc       = model.Desc;
                    heritageObject.BuildingId = model.BuildingId;
                    heritageObject.Building   = _manager.BuildingRepository.Get(model.BuildingId);
                    _manager.HeritageObjectRepository.Update(heritageObject);
                    //return Redirect("/HeritageObject/Index");
                    return(Redirect("/admin/heritageobject"));
                }
            }
            return(View(model));
        }
Exemple #3
0
        public async Task <ActionResult> Delete(int id)
        {
            HeritageObject heritageObject = _manager.HeritageObjectRepository.Get(id);

            if (heritageObject != null)
            {
                _manager.HeritageObjectRepository.Delete(id);
            }
            return(Redirect("/admin/heritageobject"));
        }
Exemple #4
0
        public async Task <IActionResult> Edit(int id)
        {
            ViewBag.Buildings = _manager.BuildingRepository.GetAll();
            HeritageObject heritageObject = _manager.HeritageObjectRepository.Get(id);

            if (heritageObject == null)
            {
                return(NotFound());
            }

            EditHeritageObjectViewModel model = new EditHeritageObjectViewModel
            {
                Id         = heritageObject.Id,
                Type       = heritageObject.Type,
                Condition  = heritageObject.Condition,
                ShortDesc  = heritageObject.ShortDesc,
                ImagePath  = heritageObject.Image,
                Desc       = heritageObject.Desc,
                BuildingId = heritageObject.BuildingId
            };

            return(View(model));
        }
Exemple #5
0
        public async Task <IActionResult> EditComment(int id)
        {
            Comment        comment        = _manager.CommentRepository.Get(id);
            HeritageObject heritageObject = _manager.HeritageObjectRepository.Get(comment.HeritageObjectId);

            if (comment == null)
            {
                return(NotFound());
            }

            CommentViewModel model = new CommentViewModel
            {
                Id   = comment.Id,
                Text = comment.Text,
                //Time = comment.Time,
                //IsEdited = comment.IsEdited,
                HeritageObjectId = comment.HeritageObjectId,
                HeritageObject   = heritageObject,
                UserId           = comment.UserId
            };

            return(View(model));
        }