public TypeModel AddType(AddTypeModel model)
        {
            var command = $@"
            INSERT INTO Type(
                Name,
                Description,
                P2PPlayCount,
                IsContinuous)
            OUTPUT Inserted.Id
            VALUES(
                @Name,
                @Description,
                @P2PPlayCount,
                @IsContinuous)";

            var result = ExecCommandScaler <long>(command, model);

            if (result != 0)
            {
                return new TypeModel
                       {
                           Id           = result,
                           Name         = model.Name,
                           Description  = model.Description,
                           P2PPlayCount = model.P2PPlayCount,
                           IsContinuous = model.IsContinuous
                       }
            }
            ;

            return(null);
        }
 public IActionResult AddType(AddTypeModel model)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("Error", "Home", new { errorType = 2 }));
     }
     if (model.Name == null)
     {
         return(RedirectToAction("Error", "Home", new { errorType = 3 }));
     }
     _type.AddType(new TypeOfProduct {
         Name = model.Name
     });
     return(RedirectToAction("AdminProducts", "Admin"));
 }
Exemple #3
0
        public ActionResult AddType(AddTypeModel model, int?id)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var _Context = new ApplicationContext())
            {
                // current admin id
                var currentAdmin = _Context.Users.Single(m => m.Email == User.Identity.Name).UserId;

                // if new category
                if (id.Equals(null))
                {
                    // add new category
                    var create = _Context.Type_Details;
                    create.Add(new Type_Details
                    {
                        Type_Name   = model.Name,
                        Description = model.Description,
                        Added_By    = currentAdmin,
                        Added_Date  = DateTime.Now,
                        IsActive    = true
                    });

                    _Context.SaveChanges();
                }
                // update existing category
                else
                {
                    var update = _Context.Type_Details.Single(m => m.Type_Id == id);
                    model.MaptoModel(update);
                    update.Edited_By   = currentAdmin;
                    update.Edited_Date = DateTime.Now;

                    _Context.SaveChanges();
                }
            }
            return(RedirectToAction("ManageType"));
        }
Exemple #4
0
 public TypeModel AddType([FromBody] AddTypeModel model)
 {
     return(_typeLib.AddType(model));
 }