public ActionResult DeleteConfirmed(Guid id)
        {
            ProductTheme productTheme = db.ProductThemes.Find(id);

            productTheme.IsDeleted    = true;
            productTheme.DeletionDate = DateTime.Now;

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public IActionResult UpdateTheme(int id, ProductTheme theme)
        {
            var updatedTheme = _themeRepo.Update(id, theme);

            if (_themeRepo.GetThemeById(id) == null)
            {
                return(NotFound("We could not delete this record because we did not find a product theme with that ID. Please try again."));
            }

            return(Ok(updatedTheme));
        }
 public ActionResult Edit([Bind(Include = "Id,Title,IsActive,CreationDate,LastModifiedDate,IsDeleted,DeletionDate,Description")] ProductTheme productTheme)
 {
     if (ModelState.IsValid)
     {
         productTheme.IsDeleted       = false;
         db.Entry(productTheme).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productTheme));
 }
        // GET: ProductThemes/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductTheme productTheme = db.ProductThemes.Find(id);

            if (productTheme == null)
            {
                return(HttpNotFound());
            }
            return(View(productTheme));
        }
        public ActionResult Create([Bind(Include = "Id,Title,IsActive,CreationDate,LastModifiedDate,IsDeleted,DeletionDate,Description")] ProductTheme productTheme)
        {
            if (ModelState.IsValid)
            {
                productTheme.IsDeleted    = false;
                productTheme.CreationDate = DateTime.Now;
                productTheme.Id           = Guid.NewGuid();
                db.ProductThemes.Add(productTheme);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productTheme));
        }
        public async Task UpdateThemeAsync(long Id, ProductTheme item)
        {
            var obj = await _productThemeRepository.FindByIdAsync(Id);

            if (obj != null)
            {
                obj.Title        = item.Title != null ? item.Title : obj.Title;
                obj.Status       = item.Status != null ? item.Status : obj.Status;
                obj.DateModified = DateTime.UtcNow;
                _productThemeRepository.Update(obj);
            }
            else
            {
                throw new Exception("Theme is not found");
            }
        }
예제 #7
0
        public ProductTheme Update(int id, ProductTheme theme)
        {
            var sql = @"UPDATE [dbo].[ProductThemes]
                            SET [Theme] = @theme,
                                [IsActive] = @isActive
                            OUTPUT INSERTED.*
                            WHERE Id = @id";

            using var db = new SqlConnection(_connectionString);

            var parameters = new
            {
                theme.Theme,
                theme.IsActive,
                id //shortcut for id = id since both the parameter and the property are called id
            };

            var updatedTheme = db.QueryFirstOrDefault <ProductTheme>(sql, parameters);

            return(updatedTheme);
        }
예제 #8
0
        public ProductTheme AddTheme(ProductTheme themeToAdd)
        {
            var sql = @"INSERT INTO [dbo].[ProductThemes]
                                    ([Theme],
                                     [IsActive])
                                Output inserted.Id
                                VALUES
                                    (@theme, @isActive)";

            using var db = new SqlConnection(_connectionString);

            var newId = db.ExecuteScalar <int>(sql, themeToAdd);

            var queryGetTheme = @"select *
                                from ProductThemes
                                Where Id = @id";

            var parameters = new { id = newId };

            var newTheme = db.QueryFirstOrDefault <ProductTheme>(queryGetTheme, parameters);

            return(newTheme);
        }
 public async Task AddThemeAsync(ProductTheme item)
 {
     await _productThemeRepository.AddAsync(item);
 }
예제 #10
0
        public IActionResult CreateTheme(ProductTheme newTheme)
        {
            var brandNewTheme = _themeRepo.AddTheme(newTheme);

            return(Created($"/api/themes/{newTheme.Id}", brandNewTheme));
        }