public IHttpActionResult PutSchoolAddress(int id, SchoolAddress schoolAddress)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != schoolAddress.SchoolAddress_id)
            {
                return(BadRequest());
            }

            db.Entry(schoolAddress).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SchoolAddressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetSchoolAddress(int id)
        {
            SchoolAddress schoolAddress = db.SchoolAddresses.Find(id);

            if (schoolAddress == null)
            {
                return(NotFound());
            }

            return(Ok(schoolAddress));
        }
        public IHttpActionResult DeleteSchoolAddress(int id)
        {
            SchoolAddress schoolAddress = db.SchoolAddresses.Find(id);

            if (schoolAddress == null)
            {
                return(NotFound());
            }

            db.SchoolAddresses.Remove(schoolAddress);
            db.SaveChanges();

            return(Ok(schoolAddress));
        }
Esempio n. 4
0
        public ActionResult Create(School school)
        {
            if (ModelState.IsValid)
            {
                SchoolAddress schoolAddress = new SchoolAddress();

                if (school.schoolAddress.street != null)
                {
                    school.schoolAddress.street = school.schoolAddress.street.Trim();
                }
                school.name = school.name.Trim();
                school.schoolAddress.suburb = school.schoolAddress.suburb.Trim();
                school.schoolAddress.city   = school.schoolAddress.city.Trim();

                var schl = db.Schools.ToList().Find(p => p.name.ToLower() == school.name.ToLower());
                if (schl != null)
                {
                    ModelState.AddModelError("", "This school has already been registered.");
                    return(View(school));
                }

                byte[] imageData = new byte[0];
                if (school.poImgFile != null)
                {
                    using (var binary = new BinaryReader(school.poImgFile.InputStream))
                    {
                        imageData = binary.ReadBytes(school.poImgFile.ContentLength);
                    }
                }
                school.schoolPhoto     = imageData;
                schoolAddress.province = school.schoolAddress.province;
                schoolAddress.street   = school.schoolAddress.street;
                schoolAddress.suburb   = school.schoolAddress.suburb;
                schoolAddress.city     = school.schoolAddress.city;
                schoolAddress.code     = school.schoolAddress.code;
                db.Schools.Add(school);
                schoolAddress.School = school;
                db.SchoolAddresses.Add(schoolAddress);
                db.SaveChanges();
                var stream = new Models.Stream {
                    name = "Grade 8 & 9", school = school
                };
                db.Streams.Add(stream);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(school));
        }
Esempio n. 5
0
        /// <inheritdoc/>
        public string ToDelimitedString()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;

            return(string.Format(
                       culture,
                       StringHelper.StringFormatSequence(0, 10, Configuration.FieldSeparator),
                       Id,
                       SetIdEdu.HasValue ? SetIdEdu.Value.ToString(culture) : null,
                       AcademicDegree?.ToDelimitedString(),
                       AcademicDegreeProgramDateRange?.ToDelimitedString(),
                       AcademicDegreeProgramParticipationDateRange?.ToDelimitedString(),
                       AcademicDegreeGrantedDate.HasValue ? AcademicDegreeGrantedDate.Value.ToString(Consts.DateFormatPrecisionDay, culture) : null,
                       School?.ToDelimitedString(),
                       SchoolTypeCode?.ToDelimitedString(),
                       SchoolAddress?.ToDelimitedString(),
                       MajorFieldOfStudy != null ? string.Join(Configuration.FieldRepeatSeparator, MajorFieldOfStudy.Select(x => x.ToDelimitedString())) : null
                       ).TrimEnd(Configuration.FieldSeparator.ToCharArray()));
        }
Esempio n. 6
0
 public SchoolCreatedEvent(Guid id, string name, SchoolAddress address)
 => (Id, Name, Address) = (id, name, address);