public ActionResult addWorkExperience(WorkExperience std) { std.CreationDate = DateTime.Now; std.LastModificationDate = DateTime.Now; std.EmployeeProspectId = (int)std.EmployeeProspectId; db.WorkExperiences.Add(std); try { db.SaveChanges(); } catch (DbEntityValidationException e) { string message1 = e.StackTrace; foreach (var eve in e.EntityValidationErrors) { message1 += eve.Entry.State + "\n"; foreach (var ve in eve.ValidationErrors) { message1 += String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); message1 += "\n"; } } return(Json(new { Message = message1, JsonRequestBehavior.AllowGet })); } string message = "SUCCESS"; return(Json(new { Message = message, JsonRequestBehavior.AllowGet })); }
public IActionResult Post(BookModel model) { var book = _mapper.Map <BookModel, Book>(model); _applicationDataContext.Books.Add(book); _applicationDataContext.SaveChanges(); return(Ok(book)); }
public IActionResult Post(BookCategoryModel model) { var bookCategory = _mapper.Map <BookCategoryModel, BookCategory>(model); _applicationDataContext.BookCategories.Add(bookCategory); _applicationDataContext.SaveChanges(); return(Ok(bookCategory)); }
public IActionResult Post(CategoryModel model) { var category = _mapper.Map <CategoryModel, Category>(model); _applicationDataContext.Categories.Add(category); _applicationDataContext.SaveChanges(); return(Ok(category)); }
public ActionResult Create([Bind(Include = "Id,Title")] Subject subject) { if (ModelState.IsValid) { db.Subjects.Add(subject); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(subject)); }
public ActionResult Create([Bind(Include = "prodId,prodName,prodStockQty,prodStockReq,prodPrice")] Inventory inventory) { if (ModelState.IsValid) { db.Inventories.Add(inventory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(inventory)); }
public ActionResult Create([Bind(Include = "TransId,transDate,OrNo,product,transQtyPurch,cashier")] Sales sales) { if (ModelState.IsValid) { db.Sales.Add(sales); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sales)); }
public ActionResult Create([Bind(Include = "Id,Data")] ExistingTable existingTable) { if (ModelState.IsValid) { db.ExistingTables.Add(existingTable); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(existingTable)); }
public ActionResult Create([Bind(Include = "Id,Album_Id,Quantity,TransactionDate,Price")] Transaction transaction) { if (ModelState.IsValid) { _context.Transactions.Add(transaction); _context.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Album_Id = new SelectList(_context.Albums, "Id", "Title", transaction.Album_Id); return(View(transaction)); }
public ActionResult Create([Bind(Include = "id,Name,Email,Message,Date")] ContactUs contactus) { fillUserData(); if (ModelState.IsValid) { db.ContactUs.Add(contactus); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contactus)); }
public ActionResult Create([Bind(Include = "id,Comment,Date")] ArticleComment articlecomment) { fillUserData(); if (ModelState.IsValid) { db.ArticleComments.Add(articlecomment); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(articlecomment)); }
public ActionResult AddNewQuestion(Question question, int TestId) { fillUserData(); if (ModelState.IsValid) { string category = db .QuestionCategories .Where(cat => cat.Id == question.CategoryId) .Select(cat => cat.Category) .FirstOrDefault(); question.QuestionType = category; int nextQuestionNumber = db .TestXQuestions .Where(txq => txq.TestId == TestId) .Count() + 1; db.Questions.Add(question); db.SaveChanges(); Question lastInsertedQuestion = db .Questions .OrderByDescending(q => q.Id) .FirstOrDefault(); TestXQuestion testXQuestion = new TestXQuestion() { TestId = TestId, QuestionId = lastInsertedQuestion.Id, QuestionNumber = nextQuestionNumber, IsActive = question.IsActive }; db.TestXQuestions.Add(testXQuestion); db.SaveChanges(); return(RedirectToAction("QuestionPage", new { TestId })); } // if an Error Occurred! Test test = db.Tests.FirstOrDefault(t => t.Id == TestId); if (test != null) { ViewBag.Categories = new SelectList(db.QuestionCategories.ToList(), "Id", "Category"); ViewBag.Test = test; } return(View(question)); }
public ActionResult Create([Bind(Include = "id,Sender,Receiver,Subject,Body,CreationDate,LastModificationDate")] EmailLog emaillog) { fillUserData(); if (ModelState.IsValid) { db.EmailLogs.Add(emaillog); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(emaillog)); }
public ActionResult Create(Test test) { fillUserData(); if (ModelState.IsValid) { db.Tests.Add(test); db.SaveChanges(); return(RedirectToAction("index")); } return(View(test)); }
public ActionResult Create(IdentityRole role) { fillUserData(); if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(role)); }
public ActionResult Create([Bind(Include = "Id,QuestionId,Label,points,IsActive")] Choice choice) { fillUserData(); if (ModelState.IsValid) { db.Choices.Add(choice); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.QuestionId = new SelectList(db.Questions, "Id", "QuestionType", choice.QuestionId); return(View(choice)); }
public int Add(TiendasEntitie tienda) { if (tienda.Nombre == null) { return(0); } else { _context.Tiendas.Add(tienda); _context.SaveChanges(); return(tienda.Id); } }
public ActionResult AddToCart(int id) { var customer = GetCustomer(); Album album = _context.Albums.SingleOrDefault(a => a.Id == id); var c = _context.Cart.ToList(); bool match = false; foreach (var e in c) { if (album.Id == e.Album_Id && customer == e.Customer) { e.Quantity++; match = true; break; } else { } } if (match == false) { Cart cartItem = new Cart() { Album = album, Album_Id = album.Id, Quantity = 1, Customer = customer }; _context.Cart.Add(cartItem); } else { } album.Stock--; _context.SaveChanges(); var albums = _context.Albums.ToList(); var cart = _context.Cart.ToList(); var viewModel = new ShoppingCartViewModel { Albums = albums, Cart = cart, Customer = GetCustomer() }; return(View("CartView", viewModel)); }
public ActionResult Register(int?TestId, string employee_code) { // register the user for the Test Employees employee = db .Employees .Include("Registrations") .FirstOrDefault(emp => emp.EId.Equals(employee_code, StringComparison.InvariantCultureIgnoreCase)); Test test = db.Tests.FirstOrDefault(t => t.Id == TestId); List <Registration> registrations = db .Registrations .Where(reg => reg.TestId == TestId && reg.EmployeeId == employee.Id).ToList(); // If the employee has already registered for the Test ---> var _maxNumberOfAllowedExams = ParameterRepository.findByCode("max_number_of_allowed_exams"); int maxNumberOfAllowedExams = Int32.Parse(_maxNumberOfAllowedExams); if (registrations.Count() >= maxNumberOfAllowedExams) { Session["TOKEN"] = registrations[0].Token; TempData["errMessage"] = "You can only take the test twice, If you believe that there is something wrong please contact your direct manager"; return(RedirectToAction("InstructionPage", new { TestId, employee_code })); //return RedirectToAction("FinalResult", new { TestId, token = registrations[0].Token }); } // Create New Registration else { Registration newRegistration = new Registration() { EmployeeId = employee.Id, TestId = TestId.GetValueOrDefault(), RegistrationDate = DateTime.Now, ExpiresDate = DateTime.Now.AddMinutes(test.DurationInMinutes), Token = Guid.NewGuid() }; employee.Registrations.Add(newRegistration); db.Registrations.Add(newRegistration); db.SaveChanges(); Session["TOKEN"] = newRegistration.Token; Session["ExpireDate"] = newRegistration.ExpiresDate; Session.Timeout = test.DurationInMinutes; } return(RedirectToAction("EvalPage", new { @token = Session["TOKEN"] })); }
public ActionResult Create([Bind(Include = "id,Name,Code,Value")] SystemParameter systemparameter) { fillUserData(); if (ModelState.IsValid) { systemparameter.CreationDate = DateTime.Now; systemparameter.LastModificationDate = DateTime.Now; db.SystemParameters.Add(systemparameter); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(systemparameter)); }
public ActionResult Create([Bind(Include = "Id,RegistrationDate,ExpiresDate,Token,TestId,EmployeeId")] Registration registration) { fillUserData(); if (ModelState.IsValid) { db.Registrations.Add(registration); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "Name", registration.EmployeeId); ViewBag.TestId = new SelectList(db.Tests, "Id", "Name", registration.TestId); return(View(registration)); }
public IActionResult Post(TeacherModel model) { var teacher = _mapper.Map <TeacherModel, Teacher>(model); if (!_validator.Valido(teacher)) { return(Ok(_validator.Errors)); } _applicationDataContext.Teachers.Add(teacher); _applicationDataContext.SaveChanges(); return(Ok(teacher)); }
public ActionResult Create(Job job) { fillUserData(); if (ModelState.IsValid) { job.CreationDate = DateTime.Now; job.LastModificationDate = DateTime.Now; db.Jobs.Add(job); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(job)); }
public ActionResult Create([Bind(Include = "id,startDate,EndDate,Duration,EmployeeId,Status")] EmployeesVacation employeesvacation) { fillUserData(); if (ModelState.IsValid) { employeesvacation.CreationDate = DateTime.Now; employeesvacation.LastModificationDate = DateTime.Now; employeesvacation.Duration = (employeesvacation.EndDate - employeesvacation.startDate).Days; db.EmployeesVacations.Add(employeesvacation); db.SaveChanges(); return(RedirectToAction("EmployeeVacation", new { Employeeid = employeesvacation.EmployeeId })); } return(View(employeesvacation)); }
public AlbumDto CreateAlbum(AlbumDto albumDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var album = Mapper.Map <AlbumDto, Album>(albumDto); _context.Albums.Add(album); _context.SaveChanges(); albumDto.Id = album.Id; return(albumDto); }
/// <summary> /// Adding New User to the database. /// </summary> /// <param name="fName"></param> /// <param name="lName"></param> /// <param name="userType"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="regDate"></param> /// <param name="address"></param> /// <param name="tel"></param> /// <param name="createdAt"></param> public static int addUser(string fName, string lName, string userType, string userName, string password, DateTime regDate, string address, string tel, DateTime createdAt, DateTime updatedAt) { try { int isAdd = 0; var Reg = new UsersReg { first_name = fName, last_name = lName, user_type = Aids.PickEnum(userType), user_name = userName, password = password.EncryptText("magic_encrypt1256"), reg_date = regDate, address = address, tel = tel, created_at = createdAt, updated_at = updatedAt }; using (var context = new ApplicationDataContext()) { context.staffs.Add(Reg); isAdd = context.SaveChanges(); } return(isAdd); } catch (Exception) { throw; } }
public ActionResult Update([FromBody] Brownbag.Data.Models.Post entity) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } /* * EF Core 2.0+ Assumes if Id = 0 then you want to add. * So we can effectively use the same method for create * and update since leaving out the Id or explicitly * setting it to 0 will let EF know that its an add not * update */ _context.Posts.Update(entity); _context.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("Generic Error", "Something went wrong, please contact administrator" + ex); return(BadRequest(ModelState)); } return(Json(new[] { entity })); }
public ActionResponse Save(UserDto obj) { try { var dao = Mapper.Map <UserDao>(obj); if (obj.Id == default(Guid)) { var response = _userManager.Create(dao); if (!response.Succeeded) { return(ActionResponse.Failure(response.Errors.ToArray())); } var user = _userManager.FindByEmail(obj.Email); if (user == null) { return(ActionResponse.Failure($"User not found for email={obj.Email.ToString()}")); } return(ActionResponse.Succeed()); } else { using (ApplicationDataContext ctx = new ApplicationDataContext()) { ctx.Entry(dao).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } return(ActionResponse.Succeed()); } } catch (Exception exc) { return(ActionResponse.Failure(exc.Message)); } }
public static int UpdateQuantityandNewPrice(int id, int quantity, decimal Newprice) { try { int saves = 0; using (var context = new ApplicationDataContext()) { prodsales = context.products_sales.Where(s => s.id == id).FirstOrDefault <ProductSales>(); } if (prodsales != null) { prodsales.amount_paid = Newprice; prodsales.quantity -= quantity; using (var context = new ApplicationDataContext()) { context.Entry(prodsales).State = EntityState.Modified; saves = context.SaveChanges(); } } return(saves); } catch (Exception) { throw; } }
public static int add(int salesId, int productId, int quantity, decimal amountPaid, DateTime salesDate, decimal originalPrice) { try { int added = 0; var prodSales = new ProductSales() { sales_id = salesId, product_id = productId, quantity = quantity, amount_paid = amountPaid, sales_date = salesDate, original_price = originalPrice }; using (var context = new ApplicationDataContext()) { context.products_sales.Add(prodSales); added = context.SaveChanges(); } return(added); } catch (Exception) { throw; } }