public UserViewModel Get(string id) { var user = dbContext.AspNetUsers.Find(id); if (user == null) { return(null); } if (user.AspNetUserRoles.Count == 0) { var role = dbContext.AspNetRoles.ToList().Find(x => x.Name == "User"); user.AspNetUserRoles.Add(new AspNetUserRoles { UserId = user.Id, RoleId = role.Id }); dbContext.SaveChanges(); } var userViewModel = new UserViewModel { Id = user.Id, Name = user.UserName, Image = user.Image, Biography = user.Biography, Country = user.Country, Role = user.AspNetUserRoles.FirstOrDefault(x => x.UserId == user.Id).Role.Name }; return(userViewModel); }
public ActionResult Create([Bind(Include = "Id,City,StreetName,WorkTime,OnlineOrder")] Shop shop) { if (ModelState.IsValid) { db.CamShop.Add(shop); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shop)); }
public ActionResult Create([Bind(Include = "Id,Name")] City city) { if (ModelState.IsValid) { db.Cities.Add(city); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(city)); }
public ActionResult Create([Bind(Include = "Id,Type,Bedrooms,Rooms,Area,Floor,ResidentialDistrict,City,Price,Year,Extras")] Property property) { if (ModelState.IsValid) { db.Properties.Add(property); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(property)); }
public void Saved() { ctx.SaveChanges(); }
public void Create(T item) { Context.Set <T>().Add(item); Context.SaveChanges(); }
public virtual int SaveChanges() => context.SaveChanges();