public AttachStudentResultModel PostAddress(StudentAddressViewModel data)
        {
            var res = new AttachStudentResultModel
            {
                Done     = false,
                Lines    = new List <LineModel>(),
                Stations = new List <StationModel>()
            };

            try
            {
                using (var logic = new tblStudentLogic())
                {
                    var st = logic.getStudentByPk(data.StudentId);
                    if (st != null)
                    {
                        if (st.cityId != data.CityId ||
                            st.streetId != data.StreetId ||
                            st.houseNumber != data.HouseNumber)
                        {
                            st.street      = data.Street;
                            st.streetId    = data.StreetId;
                            st.city        = data.City;
                            st.cityId      = data.CityId;
                            st.houseNumber = data.HouseNumber;
                            st.Lat         = null;
                            st.Lng         = null;
                            tblStudentLogic.update(st);

                            //disconnect from all lines
                            var detachResult = logic.RemoveStudentFromAllStations(st.pk);
                            res.Student = new StudentShortInfo(st);

                            res.Stations = detachResult.Stations.Select(d => new StationModel(d)).ToList();
                            res.Lines    = detachResult.Lines.Select(d => new LineModel(d)).ToList();

                            res.Done = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                res.Done = false;
            }
            return(res);
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("Address,StudentName")] StudentAddressViewModel studentAddress)
        {
            StudentAddress theStudentAddress = new StudentAddress();

            if (ModelState.IsValid)
            {
                var student = await _context.Students
                              .FirstOrDefaultAsync(s => s.Name.Equals(studentAddress.StudentName));

                theStudentAddress.StudentId = student.Id;
                theStudentAddress.Address   = studentAddress.Address;
                _context.Add(theStudentAddress);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StudentId"] = new SelectList(_context.Students, "Id", "Id", studentAddress.StudentId);
            return(View(theStudentAddress));
        }
        public StudentAddressViewModel GetAddress(int id)
        {
            StudentAddressViewModel res = null;

            using (var logic = new tblStudentLogic())
            {
                var st = logic.getStudentByPk(id);
                if (st != null)
                {
                    res = new StudentAddressViewModel
                    {
                        StudentId   = st.pk,
                        City        = st.city,
                        CityId      = st.cityId ?? 0,
                        Street      = st.street,
                        StreetId    = st.streetId ?? 0,
                        HouseNumber = st.houseNumber,
                        Confirm     = st.registrationStatus
                    };
                }
            }
            return(res);
        }