public void EnsureSeedData() { _context.Database.EnsureCreated(); if (!_context.Customers.Any()) { _context.Customers.RemoveRange(_context.Customers); _context.SaveChanges(); Customer customer = new Customer(); customer.FirstName = "Dimitar"; customer.LastName = "Ivanov"; customer.Age = 35; Customer customer_2 = new Customer(); customer_2.FirstName = "Alexander"; customer_2.LastName = "Yanev"; customer_2.Age = 31; _context.Add(customer); _context.Add(customer_2); _context.SaveChanges(); } }
public ActionResult EditName(Data data) { ProfileModel model = new ProfileModel() { }; using (CustomDbContext db = new CustomDbContext()) { string currentPerson = s.user; if (currentPerson != null && data.username != null) { model = db.ProfileModel.SingleOrDefault(x => x.UserName == currentPerson); if (model != null) { if (data.username != null) { if (data.username != model.Name) { model.Name = data.username; db.SaveChanges(); } } else { model.Name = ""; db.SaveChanges(); } } } } return(Content(model.Name)); }
//POST public ActionResult Tegs(Data data) { ProfileModel model = new ProfileModel() { }; using (CustomDbContext db = new CustomDbContext()) { string currentPerson = s.user; if (currentPerson != null) { model = db.ProfileModel.SingleOrDefault(x => x.UserName == currentPerson); if (model != null) { if (model.Tegs != null && data.addTeg != null) { bool tagExists = false; var tags = model.Tegs.Split('|'); foreach (var tag in tags) { if (tag == data.addTeg && tag != "") { tagExists = true; break; } } if (!tagExists) { model.Tegs += data.addTeg + '|'; db.SaveChanges(); } } if ((model.Tegs == null || model.Tegs == "") && data.addTeg != null) { model.Tegs += data.addTeg + '|'; db.SaveChanges(); model.tegs.Add(data.addTeg); } else { var splitTegs = model.Tegs.Split('|'); foreach (var el in splitTegs) { if (el != "") { model.tegs.Add(el); } } } } } } return(PartialView(model)); }
public IActionResult Post([FromBody] object valueObj) { var value = JsonConvert.DeserializeObject <T>(valueObj.ToString()); var entityEntry = _dbSet.Add(value); _context.SaveChanges(); return(Json(entityEntry.Entity)); }
public void MongoDbBucketSet() { var connection = BenchmarkDb.GetConnection(); var date = new DateTime(2000, 1, 1); using (var context = new CustomDbContext(connection)) { //Add for (var i = 0; i < NumberOfGroups; i++) { for (var j = 0; j < EntitiesPerGroup; j++) { var v = i * EntitiesPerGroup + j; context.TestBucketModels.Add(new TestBucketGroup { Name = "TestModel" }, new TestBucketItem { Date = date.AddDays(v), OtherReference = v, NestedModel = new NestedTestModel { NestedName = $"TestModel {v}", NestedReference = v } }); } context.SaveChanges(); } //Read for (var i = 0; i < EntitiesPerGroup; i++) { context.TestBucketModels.WithGroup(new TestBucketGroup { Name = "TestModel" }).Sum(t => t.OtherReference); } //Remove context.TestBucketModels.Remove(new TestBucketGroup { Name = "TestModel" }); context.SaveChanges(); } }
public ActionResult SetMentorRate(Data data) { string currentMent = s.user; ProfileModel ment = new ProfileModel() { }; if (currentMent != null && currentMent != "") { using (CustomDbContext db = new CustomDbContext()) { ment = db.ProfileModel.SingleOrDefault(x => x.UserName == data.name); if (ment != null) { if (ment.Rates != null) { var rates = ment.Rates.Split('|'); int MentorRate = 0; foreach (var rate in rates) { MentorRate += Convert.ToInt32(rate); } data.rate = (Convert.ToInt32(data.rate) + 1).ToString(); MentorRate += Convert.ToInt32(data.rate); ment.Rate = MentorRate / (rates.Length - 1); ment.Rates += data.rate + "|"; ment.WhoRates += currentMent + "|"; } } db.SaveChanges(); } } return(Content((ment.Rate - 1).ToString())); }
public void Diff() { var dbContextOptionsBuilder = new DbContextOptionsBuilder <CustomDbContext>() .UseInMemoryDatabase("in-memory-db"); using var dbContext = new CustomDbContext(dbContextOptionsBuilder.Options); var person = new Person(new PersonName("First", "M", "Last", "First M Last")); var permissionType = new PermissionType(new PermissionTypeData("example permission", 1)); var personPermission = new PersonPermission(person.Id, permissionType.Id); dbContext.Add(person); dbContext.Add(personPermission); dbContext.Add(permissionType); dbContext.SaveChanges(); var result1 = dbContext.PersonPermissions.Where(e => e.Id == personPermission.Id).Select(MapFromDomain1).FirstOrDefault(); var result2 = dbContext.PersonPermissions.Where(e => e.Id == personPermission.Id).Select(MapFromDomain2).FirstOrDefault(); //Fails Assert.Equal(result1.PersonFirstName, result2.PersonFirstName); // result2.PersonFirstName == "First M Last" Assert.Equal(result1.PersonLastName, result2.PersonLastName); // result2.PersonFirstName == "M" Assert.Equal(result1.PersonMiddleInitial, result2.PersonMiddleInitial); // result2.PersonFirstName == null Assert.Equal(result1.PersonFullName, result2.PersonFullName); // result2.PersonFirstName == "Last" }
public ActionResult EntryContactInfo() { contactu contactus = new contactu(); contactus.Name = Request["name"]; contactus.Email = Request["email"]; contactus.Subject = Request["subject"]; contactus.Message = Request["message"]; contactus.Review = Request["review"]; System.Diagnostics.Debug.WriteLine("-----Contact Us-------------------------------"); System.Diagnostics.Debug.WriteLine("Before"); System.Diagnostics.Debug.WriteLine("-----Contact Us-------------------------------"); if (ModelState.IsValid) { dbContext.contactus.Add(contactus); dbContext.SaveChanges(); return(RedirectToAction("Index")); } System.Diagnostics.Debug.WriteLine("-----Contact Us-------------------------------"); System.Diagnostics.Debug.WriteLine(Request["name"]); System.Diagnostics.Debug.WriteLine("-----Contact Us-------------------------------"); return(RedirectToAction("Index")); }
public ActionResult WorklistEdit([Bind(Include = "")] work work) { if (Session["username"] == null) { return(RedirectToAction("Index", "Home")); } if (Session["uType"] == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { Db.Entry(work).State = EntityState.Modified; Db.SaveChanges(); } return(RedirectToAction("Worklist")); }
public ActionResult PublishArticle(string articleId)//ArticleModel model { //Decorator.SavaArticle d = new Decorator.Publish(new Decorator.ImplementSave()); //d.saveToDb(model); using (CustomDbContext db = new CustomDbContext()) { var myModel = db.ArticleModel.FirstOrDefault(x => x.articleID == articleId); myModel.isPublished = true; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult RemoveTegs(Data data) { ProfileModel model = new ProfileModel() { }; using (CustomDbContext db = new CustomDbContext()) { string currentPerson = s.user; if (currentPerson != null && data.removeTeg != null) { model = db.ProfileModel.SingleOrDefault(x => x.UserName == currentPerson); if (model != null) { if (model.Tegs != null) { var tags = model.Tegs.Split('|'); for (int i = 0; i < tags.Length - 1; i++) { if (tags[i] == data.removeTeg && tags[i] != "" && data.removeTeg != "") { Array.Clear(tags, i, 1); } } model.Tegs = ""; for (int i = 0; i < tags.Length - 1; i++) { if (tags[i] != null) { model.Tegs += tags[i] + '|'; } } db.SaveChanges(); var splitTegs = model.Tegs.Split('|'); foreach (var el in splitTegs) { if (el != "") { model.tegs.Add(el); } } } } } } return(PartialView("Tegs", model)); }
public IActionResult Login(LoginRequest request) { //TODO Here we should check the credentials! Here we are just taking the first user. AppUser user = _context.Users.ToList().First(); if (user == null) { return(NotFound()); } Claim[] userclaim = new[] { new Claim(ClaimTypes.Name, user.UserName), new Claim(ClaimTypes.Role, "user"), new Claim(ClaimTypes.Role, "admin") //Add additional data here }; SymmetricSecurityKey key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["SecretKey"])); SigningCredentials creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); JwtSecurityToken token = new JwtSecurityToken( issuer: "https://localhost:5001", audience: "https://localhost:5001", claims: userclaim, expires: DateTime.Now.AddMinutes(1), signingCredentials: creds ); user.RefreshToken = Guid.NewGuid().ToString(); user.RefreshTokenExpirationDate = DateTime.Now.AddDays(1); _context.SaveChanges(); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), refreshToken = user.RefreshToken })); }
public ActionResult DeleteArticle(string articleId) { using (CustomDbContext db = new CustomDbContext()) { var modelToDelete = db.ArticleModel.FirstOrDefault(x => x.articleID == articleId); if (modelToDelete != null) { db.ArticleModel.Remove(modelToDelete); db.SaveChanges(); } //TODO: else return error page } return(RedirectToAction("Index")); }
public ActionResult RequestsPartial(Data data) { RequestModel reqModel = new RequestModel(); if (string.IsNullOrEmpty(data.inputRequestName)) { ModelState.AddModelError("inputRequestName", "Введіть назву заявки."); } if (string.IsNullOrEmpty(data.inputRequestText)) { ModelState.AddModelError("inputRequestText", "Введіть текст заявки."); } if (data.tagList == null) { ModelState.AddModelError("tagList", "Оберіть теги."); } if (ModelState.IsValid) { using (CustomDbContext db = new CustomDbContext()) { string currentPerson; if (Request.Cookies["UserId"] != null) { currentPerson = Convert.ToString(Request.Cookies["UserId"].Value); int count = db.RequestsModel.Count(x => x.createdBy == currentPerson); //? if (count == 0) //если это первая заявка у пользователя { reqModel.requestId = currentPerson + "_1"; } else { reqModel.requestId = currentPerson + "_" + (count + 1); } reqModel.requestName = data.inputRequestName; reqModel.requestText = data.inputRequestText; reqModel.requestState = "request not resolved"; reqModel.createdBy = currentPerson; reqModel.createdAt = DateTime.Now; reqModel.SelectedTeg = data.tagList; //if (reqModel.requestName == null) // reqModel.requestName = reqModel.requestText.Substring(0, 10); db.RequestsModel.Add(reqModel); db.SaveChanges(); } } } //return PartialView("_RequestsPartial"); return(RedirectToAction("LoadStudentRequests")); //return View("CreateRequest");//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
public ActionResult IsMessageRead(ChatMessageModel data) { using (var db = new CustomDbContext()) { var list = db.ChatMessages.Where(x => (x.FromUser == data.FromUser || x.ToUser == data.FromUser) && (x.FromUser == data.ToUser || x.ToUser == data.ToUser)).ToList(); foreach (var item in list) { item.isMessageSent = true; } db.SaveChanges(); } return(Content("")); }
public int Add(User user) { if (user == null) { return(0); } if (_dbContext.Users.Any(e => e.Name == user.Name)) { return(0); } _dbContext.Users.Add(user); _dbContext.SaveChanges(); return(user.Id); }
private static void AddTestData(CustomDbContext context) { AppUser appUser = new AppUser { Email = "*****@*****.**", EmailConfirmed = true, UserName = "******" }; PasswordHasher <AppUser> pass = new PasswordHasher <AppUser>(); appUser.PasswordHash = pass.HashPassword(appUser, "asd123"); context.Users.Add(appUser); context.SaveChanges(); }
public ActionResult EditPhoto(Data data) { byte[] buffer = new byte[0]; ProfileModel model = new ProfileModel() { }; if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { var file = System.Web.HttpContext.Current.Request.Files["HelpSectionImages"]; MemoryStream ms = new MemoryStream(); //var bytes = System.IO.File.ReadAllBytes(pic); buffer = new byte[file.ContentLength]; file.InputStream.Read(buffer, 0, file.ContentLength); using (CustomDbContext db = new CustomDbContext()) { string currentPerson = s.user; if (currentPerson != null) { var user = db.UserProfiles.SingleOrDefault(x => x.UserName == currentPerson); if (user != null) { var myModel = db.ProfileModel.SingleOrDefault(x => x.UserName == currentPerson); myModel.UserPhoto = buffer; model = myModel; db.SaveChanges(); } else { ModelState.AddModelError("Error", "Error"); } } } //model.UserPhoto = buffer; } return(Content(Convert.ToBase64String(buffer, Base64FormattingOptions.None))); }
public ActionResult MarkAsCanceled(RequestsList resolvThisReq, string requestId) { using (CustomDbContext db = new CustomDbContext()) { var r = db.RequestsModel.SingleOrDefault(x => x.requestId == requestId); if (r != null) { r.requestState = "request canceled"; } db.SaveChanges(); } //RequestsList requestsModel = new RequestsList(); //RequestModel req = new RequestModel("user1_5", "Help with 1...", "bla-bla1", null, "request canceled"); //if (req.requestState != "request not resolved" && req.requestState != "request resolved") requestsModel.reqests.Add(req); //если заявка не решена и не отменена отображаем как активные //req = new RequestModel("user1_6", "Help with 2...", "bla-bla2", null, "request canceled"); //if (req.requestState != "request not resolved" && req.requestState != "request resolved") requestsModel.reqests.Add(req); return(RedirectToAction("CanceledRequests")); //return View("StudentRequests", requestsModel.reqests); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (CustomDbContext db = new CustomDbContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "Користувач вже існує з таким ім'ям. Будь ласка, введіть інше ім'я користувача."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public void TestMethod1() { Database.SetInitializer(new DropCreateDatabaseIfModelChanges <CustomDbContext>()); string cnString = ConfigurationManager.ConnectionStrings["EFDB"].ConnectionString; CustomDbContext dc = new CustomDbContext(cnString); dc.Database.Initialize(false); var a = dc.Messages.FirstOrDefault(); Message m = new Message() { Content = "CCCC", Date = DateTime.Today, Deleted = false, SenderUsername = "******", Title = "TTTT", LastUpdate = DateTime.Now, Recipients = new List <Recipient>() { new Recipient("ivan1", null) { Deleted = false, Viewed = false, Message = new Message() { Content = "DDDD", Date = DateTime.Today, Deleted = false, SenderUsername = "******", Title = "FFFF", LastUpdate = DateTime.Now, } } } }; dc.Messages.Add(m); dc.SaveChanges(); var i = dc.Messages.Find(m); }
public ActionResult UploadPhoto() { ProfileModel model = new ProfileModel() { }; using (CustomDbContext db = new CustomDbContext()) { if (s.user != null && s.user != "") { var user = db.UserProfiles.SingleOrDefault(x => x.UserName == s.user); if (user != null) { model = db.ProfileModel.SingleOrDefault(x => x.UserName == s.user); db.SaveChanges(); } else { ModelState.AddModelError("Error", "Error"); } } } if (model != null) { if (model.UserPhoto != null) { return(Content(Convert.ToBase64String(model.UserPhoto))); } else { return(Content("error")); } } else { return(Content("error")); } }
public ActionResult MakeAdmin(int id) { if (Session["username"] == null) { return(RedirectToAction("Index", "Home")); } if (Session["uType"] == null) { return(RedirectToAction("Index", "Home")); } user user = dbContext.users.Find(id); user.type = "admin"; if (ModelState.IsValid) { dbContext.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified; dbContext.SaveChanges(); return(RedirectToAction("UserList", "AdminUser")); } return(RedirectToAction("UserList", "AdminUser")); }
public void LikeDislike(ArticleModel model) { string currentMent; if (Request.Cookies["MentorId"] != null) { currentMent = Convert.ToString(Request.Cookies["MentorId"].Value); } else { currentMent = ""; } if (currentMent != "") { string currentPerson; if (Request.Cookies["UserId"] != null) { currentPerson = Convert.ToString(Request.Cookies["UserId"].Value); } else { currentPerson = "user1"; } using (CustomDbContext db = new CustomDbContext()) { var m = db.ArticleModel.SingleOrDefault(x => x.articleID == model.articleID); if (model.SelectedTeg != null) { if (model.SelectedTeg.FirstOrDefault() == "1") { if (m.whoLikes != null) { var whoLikes = m.whoLikes; if (!m.whoLikes.Contains(currentPerson)) { m.whoLikes = whoLikes + currentPerson + " "; } } else { m.whoLikes = currentPerson + " "; } if (m.whoDislikes != null) { if (m.whoDislikes.Contains(currentPerson)) { var whoDislikes = m.whoDislikes; m.whoDislikes = whoDislikes.Replace(currentPerson, " "); } } } else if (model.SelectedTeg.FirstOrDefault() == "2") { if (m.whoDislikes != null) { var whoDislikes = m.whoDislikes; if (!m.whoDislikes.Contains(currentPerson)) { m.whoDislikes = whoDislikes + currentPerson + " "; } } else { m.whoDislikes = currentPerson + " "; } if (m.whoLikes != null) { if (m.whoLikes.Contains(currentPerson)) { var whoLikes = m.whoLikes; m.whoLikes = whoLikes.Replace(currentPerson, " "); } } } } if (m.whoLikes != null) { if (m.whoLikes.Contains(currentPerson)) { model.youAreLikeThisArticle = true; model.youAreDislikeThisArticle = false; } else { model.youAreLikeThisArticle = false; } } if (m.whoDislikes != null) { if (m.whoDislikes.Contains(currentPerson)) { model.youAreDislikeThisArticle = true; model.youAreLikeThisArticle = false; } else { model.youAreDislikeThisArticle = false; } } db.SaveChanges(); } } //return View("ShowArticles", model); }
public void Add(Orchard entity) { db.Orchards.Add(entity); db.SaveChanges(); }
/// <summary> /// Save the changes to database /// </summary> public void Save() { db.SaveChanges(); }
public ActionResult SaveArticle(ArticleData articleData)//ArticleModel model { //Decorator.SavaArticle d = new Decorator.SaveToDraft(new Decorator.ImplementSave()); //d.saveToDb(model); //Singleton s = Singleton.Instance; string currentPerson;// = s.user; string tegString = ""; if (articleData.tagList == null) { return(null);//make error page } List <string> selectedTegs = articleData.tagList.ToList(); for (int i = 0; i < selectedTegs.Count; i++) { if (i != selectedTegs.Count - 1) { tegString += selectedTegs[i] + "|"; } else { tegString += selectedTegs[i]; } } if (Request.Cookies["UserId"] != null) //если данные о пользователе записаны в куки { if (articleData.inputArticleTitle != "" && articleData.inputArticleText != "" && articleData.tagList != null) { using (CustomDbContext db = new CustomDbContext()) { string articleid; currentPerson = Convert.ToString(Request.Cookies["UserId"].Value); Random rnd = new Random(); articleid = currentPerson + rnd.Next(0, 10).ToString(); for (int i = 0; i < 3; i++) { articleid += rnd.Next(0, 10).ToString(); } var myModel = db.ArticleModel.FirstOrDefault(x => x.createdBy == currentPerson && x.articleID == articleid); //чи створював користувач вже статті if (myModel == null) //если у пользователя не было статтей c таким id { db.ArticleModel.Add(new ArticleModel { articleID = articleid, createdBy = currentPerson, articleTitle = articleData.inputArticleTitle, articleText = articleData.inputArticleText, tagList = tegString, dateOfCreation = DateTime.Now, dateOfLastEditing = DateTime.Now, isPublished = articleData.isPublished, chosenTags = selectedTegs }); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } } } } } return(RedirectToAction("Index")); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { using (CustomDbContext db = new CustomDbContext()) { db.ProfileModel.Add(new ProfileModel { UserName = model.UserName }); db.SaveChanges(); } // Attempt to register the user try { string role = ""; if (model.Role) { role = "mentor"; } else { role = "student"; } using (CustomDbContext db = new CustomDbContext()) { var user = db.ProfileModel.SingleOrDefault(x => x.UserName == model.UserName); Image image = Image.FromFile(HostingEnvironment.MapPath("~/Images/userphoto.png")); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] b = memoryStream.ToArray(); user.UserPhoto = b; db.SaveChanges(); } WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new { EmailAddress = model.EmailAddress, Role = role }); WebSecurity.Login(model.UserName, model.Password); HttpCookie cookie = new HttpCookie("UT"); GenerateToken gt = new GenerateToken(); var jsonObj = gt.GenerateLocalAccessTokenResponse(model.UserName); JsonSerializer serializer = new JsonSerializer(); UserToken u = (UserToken)serializer.Deserialize(new JTokenReader(jsonObj), typeof(UserToken)); // Установить значения в нем cookie.Value = u.access_token; //cookie["Country"] = "ru-ru"; // Добавить куки в ответ Response.Cookies.Add(cookie); // Создать объект cookie-набора cookie = new HttpCookie("UserId"); // Установить значения в нем cookie.Value = model.UserName; // Добавить куки в ответ Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Profile")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult SaveReqest(RequestModel req) { Singleton s = Singleton.Instance; string currentPerson; currentPerson = s.user; using (CustomDbContext db = new CustomDbContext()) { if (db.ProfileModel.SingleOrDefault(x => x.UserName == currentPerson).Tegs != null) { string[] currentPersonTegs = db.ProfileModel.SingleOrDefault(x => x.UserName == currentPerson).Tegs.Split('|'); List <ProfileModel> mentorListWithTegs = new List <ProfileModel>(); var mentorList = db.UserProfiles.Where(x => x.Role == "mentor"); if (mentorList != null) { foreach (var m in mentorList) { for (int i = 0; i < currentPersonTegs.Length; i++) { string currentTeg = currentPersonTegs[i]; if (currentTeg != "") { var currentMentor = m.UserName; using (CustomDbContext db2 = new CustomDbContext()) { var ment = db2.ProfileModel.SingleOrDefault(x => x.UserName == currentMentor); if (ment != null) { if (ment.UserName != currentPerson) { if (ment.Tegs != null) { if (ment.Tegs.Contains(currentTeg)) { if (!mentorListWithTegs.Any(x => x.UserName == ment.UserName)) { mentorListWithTegs.Add(ment); } } } } } } } } } } } } using (CustomDbContext db = new CustomDbContext()) { //string currentPerson; //if (Request.Cookies["UserId"] != null) // currentPerson = Convert.ToString(Request.Cookies["UserId"].Value); //else currentPerson = "user1"; int count = db.RequestsModel.Count(x => x.createdBy == currentPerson); if (count == 0) { req.requestId = currentPerson + "_1"; } else { req.requestId = currentPerson + "_" + (count + 1); } req.requestState = "request not resolved"; req.createdBy = currentPerson; req.createdAt = DateTime.Now; if (req.requestName == null) { req.requestName = req.requestText.Substring(0, 10); } db.RequestsModel.Add( // new RequestModel { // requestId = req.requestId, // requestName = req.requestName, // requestText = req.requestText, // requestState = req.requestState, // createdBy = req.createdBy //} req ); db.SaveChanges(); } return(RedirectToAction("LoadStudentRequests")); }
public void Add(DataHeader entity) { db.DataHeaders.Add(entity); db.SaveChanges(); }