public Vacation MapData(VacationModel v) { Vacation mappedVacation = new Vacation(); if (v != null) { if (v.Cover != null) { mappedVacation.Cover = pictureAdapter.MapData(v.Cover); } mappedVacation.PromoText = v.PromoText; mappedVacation.ContactInformation = contactInformationAdapter.MapData(v.ContactInformation, v.Id); mappedVacation.Included = itemAdapter.MapData(v.Included); mappedVacation.Cost = priceAdapter.MapData(v.Cost, v.Id); mappedVacation.NumberOfParticipants = v.NumberOfParticipants; mappedVacation.When = periodAdapter.MapData(v.When, v.Id); mappedVacation.Location = locationAdapter.MapData(v.Location); mappedVacation.Comment = commentAdapter.MapData(v.Comment, v.Id); mappedVacation.AgeRange = arAdapter.MapData(v.Leeftijd, v.Id); mappedVacation.Titel = v.Titel; mappedVacation.Id = v.Id; mappedVacation.Tax_Benefit = v.Tax_Benefit; } return mappedVacation; }
static void Main() { Vacation location_one = new Vacation("Toronto", "Cold", 500); Vacation location_two = new Vacation("Vancouver", "Rain", 750); Vacation location_three = new Vacation("Portland", "Sunny", 1000); List<Vacation> newVacation = new List<Vacation>() {location_one, location_two, location_three}; Console.WriteLine("These are the destionations we have available for you:\n"); foreach (Vacation all in newVacation) { Console.WriteLine(all.place); } Console.WriteLine("\nPlease type a figure between $100.00 & $1100.00\nThat way we know what you can afford for your trip!"); string str_userChoice = Console.ReadLine(); int userChoice = int.Parse(str_userChoice); List<Vacation> vacationChoice = new List<Vacation>(); foreach (Vacation objVacation in newVacation) { if (objVacation.cost <= userChoice) { vacationChoice.Add(objVacation); } } Console.WriteLine("Here are the locations you can travel to with your budget"); foreach (Vacation locations in vacationChoice) { Console.WriteLine(locations.place); } }
public IActionResult Put([FromBody] Vacation vacation) { VacationValidation vacationValidation = new VacationValidation(db); List <string> errorsList = vacationValidation.IsVacationValid(vacation); if (errorsList.Count == 0) { db.Update(vacation); db.SaveChanges(); return(Ok()); } return(BadRequest(errorsList)); }
private void addCaVacation() { Vacation vacation = new Vacation { EndVacation = EndVacation, StartVacation = StartVacation, VacationType = SelectedVacationType, User = SelectedUserInTeam }; dbContext.Vacation.Add(vacation); dbContext.SaveChanges(); }
public async Task <IActionResult> VacationEdit(int?id) { if (id != null) { Vacation vac = await db.Vacations.FirstOrDefaultAsync(p => p.Id == id); if (vac != null) { return(View(vac)); } } return(NotFound()); }
public IActionResult VacDel(int?id) { if (id == null) { return(RedirectToAction("Vacation")); } Vacation vac = db.Vacations.Find(id); db.Vacations.Remove(vac); db.SaveChanges(); return(Redirect("Vacation")); }
public static VacationDto AsDto(this Vacation vacation) { return(new VacationDto() { StartDate = vacation.StartDate, EndDate = vacation.EndDate, Id = vacation.Id, Days = vacation.Days, EmployeeId = vacation.EmployeeId, Status = vacation.Status, Comments = vacation.Comments }); }
public VacationDetailsViewModel GetDetails(int id) { Vacation vacation = this.Context.Vacations.Find(id); if (vacation == null) { return(null); } VacationDetailsViewModel vm = Mapper.Map <Vacation, VacationDetailsViewModel>(vacation); return(vm); }
/// <summary> /// Creates new vacation in underlying context. /// </summary> /// <param name="vacation"><see cref="Vacation"/> parameter.</param> /// <returns>Added vacation identity.</returns> public async Task <int> AddAsync(Vacation vacation) { if (vacation.Id.GetValueOrDefault() > 0) { throw new System.Exception(); } await _context.Vacations.AddAsync(vacation); await _context.SaveChangesAsync(); return(vacation.Id.Value); }
/// <summary> /// 修改假期信息 /// </summary> /// <param name="vacation"></param> /// <returns></returns> public int Update(Vacation vacation) { using (MySqlConnection conn = dapper.GetConnection()) { DynamicParameters parameters = new DynamicParameters(); parameters.Add("@_Id", vacation.Id); parameters.Add("@_DayApplyLimit", vacation.DayApplyLimit); parameters.Add("@_WeekApplyLimit", vacation.WeekApplyLimit); parameters.Add("@_MonthApplyLimit", vacation.MonthApplyLimit); int res = conn.Execute("vacation_Update", parameters, commandType: System.Data.CommandType.StoredProcedure); return(res); } }
public void LoadFromDomain(Vacation entity, IEnumerable <DonVo.CQRS.Standard21.Domain.Model.Company.Holiday> holidays) { Id = entity.Id; EmployeeId = entity.EmployeeId; EmployeeName = entity.EmployeeFullName; StartDate = entity.StartDate; EndDate = entity.EndDate; VacationTypeId = entity.VacationTypeId; VacationType = entity.VacationType.Name; VacationStatus = entity.Status.ToString(); WorkingDaysAmount = entity.GetWorkingDaysAmount(holidays); RowVersion = Convert.ToBase64String(entity.RowVersion); }
public async Task <IActionResult> Create([Bind("Id,User,StartVac,EndVac,RequestDate,Accepted")] Vacation vacation) { vacation.RequestDate = DateTime.Now; vacation.User = User.Identity.Name; if (ModelState.IsValid) { _context.Add(vacation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vacation)); }
public async Task <ActionResult <Vacation> > PostVacation(Vacation vacation) { /**to validate if balance is positive**/ if (_vacationService.VacationValidationPost(vacation)) { return(BadRequest()); } _vacationService.AddVacation(vacation); _vacationService.SaveVacation(); return(CreatedAtAction("GetVacation", new { id = vacation.ID }, vacation)); }
public async Task <IActionResult> Create([Bind("Id,User,FromDate,ToDate,DateCreation,IsIll,IsConf")] Vacation vacation) { vacation.DateCreation = DateTime.Now; vacation.User = User.Identity.Name; if (ModelState.IsValid) { _context.Add(vacation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vacation)); }
private void setInFor(Vacation a) { Random rd = new Random(); a.id = Id.Text; a.name = Name.Text; a.type = Request.Form["inlineRadioOptions"]; a.reason = Request.Form["reason"]; a.daystart = Request.Form["time1"]; a.dayover = Request.Form["time2"]; a.applytime = DateTime.Now.ToString(); a.number = rd.Next(1000000, 9999999).ToString(); }
/// <summary> /// Updates existing vacation in underlying context. /// </summary> /// <param name="vacation"><see cref="Vacation"/> parameter.</param> /// <returns>True if successful.</returns> public async Task <bool> UpdateAsync(Vacation vacation) { if (vacation.Id.GetValueOrDefault() == 0) { return(false); } _context.Entry(vacation).State = EntityState.Modified; await _context.SaveChangesAsync(); return(true); }
public ActionResult Create([Bind(Include = "VacationId,WorkerId,VacationStart,VacationEnd,VacationSortId,VacationStatus")] Vacation vacation) { if (ModelState.IsValid) { db.Vacations.Add(vacation); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.VacationSortId = new SelectList(db.VacationSorts, "VacationSortId", "VacationName", vacation.VacationSortId); ViewBag.WorkerId = new SelectList(db.Workers, "WorkerId", "WorkerName", vacation.WorkerId); return(View(vacation)); }
public VacationViewModel(Vacation vacation) { UserFullName = vacation.User?.FullName ?? ""; Id = vacation.ID; CreatedAt = vacation.CreatedAt; StartDate = vacation.StartDate; EndDate = vacation.EndDate; Status = vacation.Status; VacationType = vacation.VacationType; Comment = vacation.Comment; VacationBalance = vacation.User?.VacationBalance ?? 0; UserId = vacation.UserID ?? ""; }
public ActionResult Index(Vacation vacation) { Staff staff = Session["staff"] as Staff; if (ModelState.IsValid) { vacation.StaffID = staff.ID; db.Vacations.Add(vacation); db.SaveChanges(); return(View("Index", "Home")); } return(View()); }
// GET: Vacations/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Vacation vacation = db.Vacations.Find(id); if (vacation == null) { return(HttpNotFound()); } return(View(vacation)); }
public async Task <ActionResult <Vacation> > PostVacation([FromBody] Vacation vacation) { if (ModelState.IsValid) { _context.Vacations.Add(vacation); await _context.SaveChangesAsync(); return(CreatedAtAction("GetVacation", new { id = vacation.Id }, vacation)); } else { return(BadRequest(ModelState)); } }
public static VacationDTO GetVacationDTO(Vacation Vacation) { VacationDTO VacationDTO = new VacationDTO(); VacationDTO.describe = Vacation.describe; VacationDTO.VacationId = Vacation.VacationId; VacationDTO.EndDate = Vacation.EndDate; VacationDTO.StudentId = Vacation.StudentId; VacationDTO.EndTime = Vacation.EndTime; VacationDTO.StartDate = Vacation.StartDate; VacationDTO.EndDate = Vacation.EndDate; VacationDTO.TeacherId = Vacation.TeacherId; return(VacationDTO); }
private void lbxListVacations_DoubleClick(object sender, EventArgs e) { try { string name = lbxListVacations.SelectedValue.ToString(); Vacation vacation = VacationRepository.GetVacation(name); dtpStartDateForThisEmployee.Value = vacation.DateStartVacation; dtpEndDateForThisEmployee.Value = vacation.DateEndVacation; txtCommentForThisEmployee.Text = vacation.Description; } catch { } }
public async Task <IActionResult> Add(CalendarVacationViewModel vacationViewModel) { if (vacationViewModel.Id.GetValueOrDefault() != 0) { return(BadRequest("Id must be empty.")); } if (vacationViewModel.Type == VacationType.None) { return(BadRequest("Vacation type can not be empty.")); } if (vacationViewModel.DateFrom > vacationViewModel.DateTo) { return(BadRequest("Date from can not be greater than date to.")); } Employee employee = await _employeeRepository.GetAsync(vacationViewModel.EmployeeId); if (employee == null) { return(NotFound("Employee does not exist.")); } int userId = employee.UserId; int authenticatedUserId = Int32.Parse(User.Claims.Single(x => x.Type == ApplicationClaimTypes.UserId).Value); bool isAdmin = User.IsInRole(Roles.Admin); if (!isAdmin && userId != authenticatedUserId) { return(Unauthorized()); } if (employee.Vacations.Any(x => x.DateFrom <= vacationViewModel.DateTo && vacationViewModel.DateFrom <= x.DateTo && x.Id != vacationViewModel.Id)) { return(BadRequest("Date range intersects with other vacation.")); } Vacation vacation = new Vacation() { EmployeeId = employee.Id.Value, DateFrom = vacationViewModel.DateFrom, DateTo = vacationViewModel.DateTo, Type = vacationViewModel.Type }; vacation.Id = await _vacationRepository.AddAsync(vacation); return(CreatedAtRoute("GetVacation", new { id = vacation.Id }, vacation)); }
public async Task <ActionResult <Vacation> > NoVacation([FromBody] Vacation disableItem) { var userVacation = await _context.Vacation.FindAsync(disableItem.Id); if (userVacation == null) { return(NotFound()); } userVacation.Isactive = false; await _context.SaveChangesAsync(); return(Ok(userVacation)); }
public async Task <bool> Handle(Command request, CancellationToken cancellationToken) { Vacation vacation = await _context.Vacations.SingleOrDefaultAsync(x => x.DateAndTime == DateTime.Parse(request.DateAndTime) && x.EmployeeID == request.EmployeeId); if (vacation is null) { return(false); } _context.Remove(vacation); await _context.SaveChangesAsync(); return(true); }
public ActionResult Delete(int id, Vacation vacation) { try { Vacation selectedVacation = context.Vacations.Find(id); context.Vacations.Remove(selectedVacation); context.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IHttpActionResult> DeleteVacation(int id) { Vacation vacation = await db.Vacations.FindAsync(id); if (vacation == null) { return(NotFound()); } db.Vacations.Remove(vacation); await db.SaveChangesAsync(); return(Ok(vacation)); }
public IHttpActionResult DeleteVacation(int id) { Vacation vacation = db.Vacations.Find(id); if (vacation == null) { return(NotFound()); } db.Vacations.Remove(vacation); db.SaveChanges(); return(Ok(vacation)); }
//api/v1/vacations // Creates a new vacation for the current user. public void Post([FromBody] Vacation value) { ClaimsIdentity claimsIdentity = (ClaimsIdentity)User.Identity; Claim userClaim = claimsIdentity.FindFirst(ClaimTypes.Name); string myUsername = userClaim.Value; using (var db = new MyDbContext()) { User u = db.Users.FirstOrDefault(i => i.username == myUsername); value.user = u; db.Vacations.Add(value); db.SaveChanges(); } }
public void CreateEmployee(Emp employee) { employee.Vacations = new List <Vacation>(); Vacation vacationCasual = new Vacation { Balance = 7, EmpId = employee.Id, Used = 0, Type = "Schedual Vacation" }; Vacation vacationSchedule = new Vacation { Balance = 14, EmpId = employee.Id, Used = 0, Type = "Casual Vacation" }; employee.Vacations.Add(vacationSchedule); employee.Vacations.Add(vacationCasual); _context.Emp.Add(employee); }
private void setVacation(Vacation a) { number.Text = getNumber().ToString(); xuehao.Text = a.id; Name.Text = a.name; type.Text = a.type; reason.Text = a.reason; timestart.Text = a.daystart; timeover.Text = a.dayover; condition.Text = a.condition; agreepeople.Text = a.agreepeople; applytime.Text = a.applytime; a.number = a.number; }