Esempio n. 1
0
        public bool AddVest(Models.Domain.Vesti vest)
        {
            var newVest = new Models.EF.Vesti()
            {
                Description      = vest.Description,
                CreatedTimeStamp = vest.CreatedTimeStamp,
                Category         = vest.Category,
                Author           = vest.Author,
                Name             = vest.Name
            };

            _dbContext.Vesti.Add(newVest);

            try
            {
                _dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception($"Adding Vest failed, Details: {ex.Message}, StackTrace: {ex.StackTrace}");
            }

            var refresh = GetAllVesti();

            StoreJson(refresh);

            return(true);
        }
Esempio n. 2
0
        public bool UpdateVest(Models.Domain.Vesti vestUpdate)
        {
            var vestFromDb = _dbContext.Vesti.Where(x => x.Id == vestUpdate.Id).FirstOrDefault();

            if (vestFromDb == null)
            {
                throw new Exception($"Updating Vest failed, FAKE NEWS");
            }

            vestFromDb.Description = vestUpdate.Description;
            vestFromDb.Category    = vestUpdate.Category;
            vestFromDb.Author      = vestUpdate.Author;
            vestFromDb.Name        = vestUpdate.Name;

            try
            {
                _dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception($"Updating Vest failed, Details: {ex.Message}, StackTrace: {ex.StackTrace}");
            }

            return(true);
        }
Esempio n. 3
0
        public ActionResult SubmitForm(VestiViewModel vestiViewModel)
        {
            var vest = new Models.Domain.Vesti()
            {
                Author      = vestiViewModel.Author,
                Name        = vestiViewModel.Name,
                Id          = vestiViewModel.Id,
                Category    = vestiViewModel.Category,
                Description = vestiViewModel.Description
            };


            if (vestiViewModel.Id != 0)
            {
                var res = prodynaService.UpdateVest(vest);
            }
            else
            {
                vest.CreatedTimeStamp = DateTime.Now;

                var res = prodynaService.AddVest(vest);
            }

            var resAfterUpdate = prodynaService.GetAllVesti();

            var indexViewModel = new SveVestiViewModel();

            foreach (var item in resAfterUpdate)
            {
                indexViewModel.SveVesti.Add(new VestiViewModel()
                {
                    Name            = item.Name,
                    Id              = item.Id,
                    Description     = item.Description,
                    Author          = item.Author,
                    Category        = item.Category,
                    FormatTimeStamp = "News published at: " + item.CreatedTimeStamp.Value.Year + "-" + item.CreatedTimeStamp.Value.Month + "-" + item.CreatedTimeStamp.Value.Day + "-" + item.CreatedTimeStamp.Value.Hour + "-" + item.CreatedTimeStamp.Value.Minute + "-" + item.CreatedTimeStamp.Value.Second
                });
            }

            return(View("~/Views/Home/index.cshtml", indexViewModel));
        }