public IActionResult CreateStudy(Study study) { if (ModelState.IsValid) { int?owner = HttpContext.Session.GetInt32("loggedperson"); if (owner == null) { return(RedirectToAction("Index", "Home")); } else { Study NewStudy = new Study { StudyName = study.StudyName, PrincipleInvestigator = study.PrincipleInvestigator, StartDate = study.StartDate, EndDate = study.EndDate, Description = study.Description, UserId = (int)owner }; _context.Add(NewStudy); _context.SaveChanges(); System.Console.WriteLine("NEW STUDY", NewStudy.StudyName); return(RedirectToAction("LandingPage")); } } ViewBag.Error = "Your Product was not added, please fill out the form correctly!"; return(View("StudyForm")); }
public async Task <IActionResult> Create([Bind("FemaleParticipants,MaleParticipants,DurationInDays,TotalTimeHiking,Name,StartDate")] Trip trip) { _nutritionCalculatorService.CalculateNutrition(trip); if (ModelState.IsValid) { _context.Add(trip); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(trip)); }
public UsersViewModel createSocialUser(UsersViewModel socialModel) { Users model = new Users(); model = _mapper.Map <Users>(socialModel); model.role = Model.Enums.UserRoleEnum.customer; model.status = Model.Enums.UserStatusEnum.Active; model.userCreateDate = DateTime.Now; _mainContext.Add(model); _mainContext.SaveChanges(); return(_mapper.Map <UsersViewModel>(model)); }
public async Task <ApiResult <List <TimeEntryReadEditDto> > > PunchClock(TimeEntryCreateDto dto) { var member = await _context.Members.FirstOrDefaultAsync(m => m.Id == dto.MemberId); try { if (dto.EndTime != null) { _logger.LogWarning($"An invalid clock in for {member.FirstName} {member.LastName} was blocked from being added to the database."); return(new ApiResult <List <TimeEntryReadEditDto> > { Successful = false, Error = "Punch clock entries must not have an end time" }); } var existingEntry = await _context.TimeEntries.FirstOrDefaultAsync(t => t.MemberId == dto.MemberId && t.EndTime == null); // if an entry with no end time is found for this member, they must be clocked out if (existingEntry != null) { existingEntry.EndTime = DateTime.Now; await _context.SaveChangesAsync(); _logger.LogInformation($"{member.FirstName} {member.LastName} was successfully clocked out."); return(await GetCurrentTimeEntries()); } // clock the member in by adding a new entry var newEntry = _mapper.Map <TimeEntry>(dto); _context.Add(newEntry); await _context.SaveChangesAsync(); _logger.LogInformation($"{member.FirstName} {member.LastName} was successfully clocked in."); return(await GetCurrentTimeEntries()); } catch (Exception ex) { //TODO: add inner exceptions to all other catch statements _logger.LogError($"Something went wrong when trying to punch clock {member.FirstName} {member.LastName}.\n"); _logger.LogError($"Error: {ex.Message}"); _logger.LogError($"Inner Exception: {ex.InnerException}"); return(new ApiResult <List <TimeEntryReadEditDto> > { Successful = false, Error = $"Something went wrong when trying to punch clock {member.FirstName} {member.LastName}.\n" }); } }
public IActionResult AjaxGetContacts(string owner) { var model = _context.UserContacts.Where(el => (el.owner == owner)).SingleOrDefault(); if (model == null) { UserContacts userContacts = new UserContacts(owner, new JObject()); _context.Add(userContacts); _context.SaveChanges(); model = _context.UserContacts.SingleOrDefault(el => (el.owner == owner)); } return(View(model)); }
public async Task <IActionResult> Create([Bind("BillPayID,AccountNumber,PayeeID,Amount,ScheduleDate,Period,ModifyDate")] BillPay billPay) { // input fixed values billPay.ModifyDate = DateTime.UtcNow; billPay.Status = BillStatus.Normal; billPay.ScheduleDate = DateTime.SpecifyKind(billPay.ScheduleDate, DateTimeKind.Local).ToUniversalTime(); // input validation if (billPay.ScheduleDate <= DateTime.UtcNow) { ModelState.AddModelError(nameof(billPay.ScheduleDate), "Schedule time must be after this time"); } if (ModelState.IsValid) { _context.Add(billPay); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } // operation when error occurs var customerAccounts = _context.Customers.FirstOrDefault(c => c.CustomerID == CustomerID).Accounts; ViewData["AccountNumber"] = new SelectList(customerAccounts, "AccountNumber", "AccountNumber"); ViewData["PayeeID"] = new SelectList(_context.Payees, "PayeeID", "PayeeName"); ViewData["Period"] = new SelectList(Enum.GetValues(typeof(BillPeriod))); return(View(billPay)); }
public IActionResult addproduct(Product products) { Console.WriteLine("this is a test ***************************"); int?loggedperson = HttpContext.Session.GetInt32("loggedperson"); if (ModelState.IsValid) { Console.WriteLine("step1"); Product NewProduct = new Product { name = products.name, description = products.description, startingbid = (int)products.startingbid, date = products.date, user_id = (int)loggedperson }; Console.WriteLine("step2"); _context.Add(NewProduct).ToString(); _context.SaveChanges(); System.Console.WriteLine("NEW Message", products.name); ViewBag.Success = "You have been added to the database! Please log in now!"; return(RedirectToAction("LandingPage", "Home")); } return(RedirectToAction("LandingPage", "Home")); }
public int Add(Account account) { _context.Add(account); _context.SaveChanges(); return(account.AccountId); }
public async Task <ApiResult <int> > AddMember(MemberRegisterDto dto) { try { if (dto == null) { _logger.LogWarning("User attemped registeration with null data."); return(new ApiResult <int> { Successful = false, Error = "No registration was sent to the server." }); } var member = CreateMemberProfile(dto); _context.Add(member); await _context.SaveChangesAsync(); _logger.LogInformation($"New member profile for {dto.Personal.FirstName} {dto.Personal.LastName} was successfully created"); return(new ApiResult <int> { Data = member.Id, Successful = true }); } catch (Exception ex) { _logger.LogError("An issue occured when trying to add a member: \n" + ex.Message + "\n\nStack Trace: \n" + ex.StackTrace); return(new ApiResult <int> { Successful = false, Error = "Something went wrong when trying to load the members. Please try to reload the page." }); } }
public async Task <IActionResult> Create(CategoryCreateViewModel category) { if (ModelState.IsValid) { string uniqueFileName = null; if (category.Path != null) { string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "img"); uniqueFileName = Guid.NewGuid().ToString() + "_" + category.Path.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); category.Path.CopyTo(new FileStream(filePath, FileMode.Create)); } Techlist category1 = new Techlist { Category = Convert.ToInt32(category.NameCat), Model = Convert.ToInt32(category.NameMod), Manufacturer = Convert.ToInt32(category.NameMan), Photo = uniqueFileName }; _context.Add(category1); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public User Add(User user) { _context.Add(user); _context.SaveChanges(); return(user); }
public IActionResult CreateFood(Foodviewmode food) { var userinfo = JsonConvert.DeserializeObject <Mess>(HttpContext.Session.GetString("sessionUser1234")); int id = userinfo.MessId; if (ModelState.IsValid) { string uniqueFileName = Photopathfood(food); Food newfood = new Food { FoodName = food.foodName, foodCalories = food.foodCalories, photopath = uniqueFileName, foodCategoryId = food.foodCategoryId, Price = food.price }; //if (Image != null) _Context.Add(newfood); _Context.SaveChanges(); return(RedirectToAction(nameof(FoodList))); } ViewBag.foodCategoryId = new SelectList(_Context.foodCategories.Where(m => m.MessId == id), "FoodCategoryId", "FoodCategoryName", food.foodCategoryId); return(View(food)); }
public async Task <IActionResult> CreateCompany([FromBody] CompanyModel newCompany) { if (_context.Companies.Where(company => company.Email == newCompany.Email).Count() > 0) { return(BadRequest("Email is already taken")); } if (_context.Companies.Where(company => company.Name == newCompany.Name).Count() > 0) { return(BadRequest("Company name is already taken")); } _context.Add(newCompany); try { await _context.SaveChangesAsync(); } catch (Exception ex) { ExceptionHandler.LogException(ex.StackTrace, ExceptionHandler.ErrorLevel.WARNING, _context); return(BadRequest("Failed to update Database")); } return(Ok(newCompany.Id)); }
public async Task <IActionResult> Create(FoodCategoryViewModel foodCategoryViewModel) { var userinfo = JsonConvert.DeserializeObject <Mess>(HttpContext.Session.GetString("sessionUser1234")); int id = userinfo.MessId; if (ModelState.IsValid) { FoodCategory fc = new FoodCategory { FoodCategoryName = foodCategoryViewModel.foodCategory.FoodCategoryName, MessId = id }; _context.Add(fc); await _context.SaveChangesAsync(); if (!String.IsNullOrEmpty(foodCategoryViewModel.Referer)) { return(Redirect(foodCategoryViewModel.Referer)); } // return RedirectToAction(nameof(Index)); } return(View(foodCategoryViewModel)); }
bool makeGroupIdBasketndAgreement(PaymentViewModel model) { IList <Basket> basketList = _mainContext.baskets.Where(w => w.basketStatus == BasketStatusEnum.active && w.userId == _usersService.getUserInformation(_cookieService.getSessionEmail()).userId).ToList(); Guid responsibleUser = new Guid(); responsibleUser = _usersService.getUserInformation(_cookieService.getSessionEmail()).responsibleUserId; foreach (var item in basketList) { Guid agreementsId = Guid.NewGuid(); int firstStatus = _agreementService.getFirstStatus(); item.basketGroupId = model.basketGroupId; item.basketStatus = BasketStatusEnum.done; Agreements agreementsModel = new Agreements(); agreementsModel.id = agreementsId; agreementsModel.appCategoryType = ApplicationCategoryTypesEnum.brand; agreementsModel.basketId = item.basketId; agreementsModel.groupId = model.basketGroupId; agreementsModel.companyIdForInvoice = Convert.ToInt32(model.selectedCompanieForInvoice); agreementsModel.statusId = firstStatus; agreementsModel.generalStatus = GeneralStatusEnum.Active; agreementsModel.paymentType = model.paymentStatus; agreementsModel.processDate = DateTime.Now; if (responsibleUser != new Guid()) { agreementsModel.responsibleUserId = responsibleUser; } AgreementsChanges agreementsChangesModel = new AgreementsChanges(); agreementsChangesModel.agreementId = agreementsId; agreementsChangesModel.comments = ""; agreementsChangesModel.generalStatus = GeneralStatusEnum.Active; agreementsChangesModel.processDate = DateTime.Now; agreementsChangesModel.status = firstStatus; agreementsChangesModel.userId = _usersService.getUserInformation(_cookieService.getSessionEmail()).userId; _mainContext.Add(agreementsChangesModel); _mainContext.Add(agreementsModel); } if (_mainContext.SaveChanges() > 0) { return(true); } else { return(false); } }
public Employers Add(Employers employers) { // TODO: FIX this _context.Add(employers); _context.SaveChanges(); return(employers); }
public string PostRegister([FromBody] Guardian value) { if (!_context.guardians.Any(user => user.GuardianName.Equals(value.GuardianName))) { Guardian tblUser = new Guardian(); tblUser.GuardianName = value.GuardianName; tblUser.phonenumber = value.phonenumber; tblUser.passward = value.passward; tblUser.messId = value.messId; try { _context.Add(tblUser); _context.SaveChanges(); return(JsonConvert.SerializeObject("register succefully")); } catch (Exception ex) { return(JsonConvert.SerializeObject(ex.Message)); } } else { return(JsonConvert.SerializeObject("User is existing in database")); } }
public override void InitialDialog() { //create drawable MainContext.Add(DrawableKaraokeTemplate = new DrawableKaraokeTemplate(Lyric) { Position = new Vector2(250, 100) }); base.InitialDialog(); }
public async Task <IActionResult> Create([Bind("Id,Name")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create([Bind("Id,Name,Calories,Fat,Carbohydrates,Fibre,Proteins,Salt")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("IdMan,NameMan")] Manufacturer manufacturer) { if (ModelState.IsValid) { _context.Add(manufacturer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(manufacturer)); }
public async Task <IActionResult> Create([Bind("Id,Name,Data,CreatedAt")] Group @group) { if (ModelState.IsValid) { _context.Add(@group); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(@group)); }
public async Task <IActionResult> Create([Bind("Id")] UserGroup userGroup) { if (ModelState.IsValid) { _context.Add(userGroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userGroup)); }
public async Task <IActionResult> Create([Bind("Id,DepartmentId,FirstName,LastName,IndexNumber")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", student.DepartmentId); return(View(student)); }
public ActionResult Index(DiaryView entryView) { var user = context.Users.Include(u => u.Entries).FirstOrDefault(u => u.UserName == User.Identity.Name); if (ModelState.IsValid) { if (entryView.Weight.HasValue) { context.WeightEntries.Add(new WeightEntry { Date = entryView.Date, Weight = entryView.Weight.Value, User = user }); } if (entryView.FoodId.HasValue && entryView.Amount.HasValue) { var d = entryView.Date; d = d.AddHours(entryView.Time.Hour); d = d.AddMinutes(entryView.Time.Minute); var entry = new Entry { Date = d, //TODO: Might not work FoodId = entryView.FoodId.Value, Quantity = entryView.Amount.Value, UnitId = entryView.UnitId, User = user }; context.Add(entry); } context.SaveChanges(); } else { entryView.Entries = context.Entries .Include(e => e.Food) .ThenInclude(f => f.Meassures) .Where(e => e.UserId == user.Id && e.Date.Date == entryView.Date.Date) .OrderBy(e => e.Date).ToList(); entryView.GroupedEntries = entryView.Entries .GroupBy(e => { var updated = e.Date.AddMinutes(30); return(new DateTime(updated.Year, updated.Month, updated.Day, updated.Hour, 0, 0, e.Date.Kind)); }).Select(cl => cl.ToList()).ToList(); entryView.Foods = new List <FoodView>(); return(View(entryView)); } return(RedirectToRoute("diary", new { controller = "Diary", action = "Index", date = entryView.Date.ToString("yyyy-MM-dd") })); }
public async Task <IActionResult> Create([Bind("Id,ClassId,Subject,AttendantLimit")] Project project) { if (ModelState.IsValid) { _context.Add(project); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClassId"] = new SelectList(_context.Classes, "Id", "Name", project.ClassId); return(View(project)); }
public async Task <IActionResult> Create([Bind("Id,DepartmentId,Name")] Specialisation specialisation) { if (ModelState.IsValid) { _context.Add(specialisation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", specialisation.DepartmentId); return(View(specialisation)); }
public async Task <IActionResult> Create([Bind("Id,DepartmentId,FirstName,LastName,WorkCategory,PhoneNumber,Mail,Password")] Lecturer lecturer) { if (ModelState.IsValid) { _context.Add(lecturer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "Name", lecturer.DepartmentId); return(View(lecturer)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Email")] ContactEntity contactEntity) { if (ModelState.IsValid) { contactEntity.Id = Guid.NewGuid(); _context.Add(contactEntity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contactEntity)); }
public async Task <IActionResult> Create([Bind("Id,Weight,Date,UserId")] WeightEntry weightEntry) { if (ModelState.IsValid) { _context.Add(weightEntry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", weightEntry.UserId); return(View(weightEntry)); }