public async Task <IActionResult> UpdateMajor(int id, MajorDTO majorDTO)
        {
            var UpdatedMajor = await UpdatingMajor(id, majorDTO);

            if (UpdatedMajor != null)
            {
                var majorMapped = _mapper.Map <MajorSendDTO>(UpdatedMajor);
                return(Ok(majorMapped));
            }
            return(ResponeError());
        }
Beispiel #2
0
 public HttpResponseMessage Put(MajorDTO toUpdate)
 {
     using (var context = new SistemaAcademico.DataModel.AcademicSystemContext())
     {
         var majorInDb = context.Majors.Where(m => m.MajorID == toUpdate.MajorID).FirstOrDefault();
         majorInDb.Description = toUpdate.description;
         majorInDb.MajorTitle  = toUpdate.MajorTitle;
         majorInDb.Area        = context.Areas.Where(a => a.Name == toUpdate.Area).FirstOrDefault();
         context.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }
Beispiel #3
0
        public IActionResult GetMajorByCode([FromBody] MajorDTO majorDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var watch = System.Diagnostics.Stopwatch.StartNew();
            var rs    = this._majorService.findScoreByMajorCode(majorDTO.majorCode, majorDTO.years);

            watch.Stop();
            var took = watch.ElapsedMilliseconds;

            if (rs == null)
            {
                return(NotFound(new JsonResponse(took, MessagesResponse.MESSAGE_NOT_FOUND, null)));
            }
            return(Ok(new JsonResponse(took, null, rs)));
        }
        private async Task <Major> UpdatingMajor(int id, MajorDTO majorDTO)
        {
            var major = await _repo.Get(id);

            if (major == null)
            {
                errorsList.Add("Kierunek nie istnieje");
                return(null);
            }

            if (IsInstitute() && GetInstituteID() != major.Institute.ID)
            {
                errorsList.Add("Nie możesz mdyfikować kierunków z innego wydziału");
                return(null);
            }

            Tools.CopyValues(major, majorDTO);

            if (IsSuperUser() && majorDTO.InstituteID != null)
            {
                var inst = await _repo.Get <Institute>((int)majorDTO.InstituteID);

                if (inst == null)
                {
                    errorsList.Add("Wydział nie istnieje");
                    return(null);
                }
                major.Institute = inst;
            }

            var updatedMajor = await Update(major);

            if (updatedMajor == null)
            {
                errorsList.Add("Nie udało się zmodyfikować kierunku");
                return(null);
            }
            return(updatedMajor);
        }
Beispiel #5
0
        public void Post(MajorDTO @new)
        {
            using (var c = new SistemaAcademico.DataModel.AcademicSystemContext())
            {
                var newMajor = new Classes.Major
                {
                    MajorTitle        = @new.MajorTitle,
                    FechaIntroduccion = DateTime.Now,
                    Area         = c.Areas.Where(a => a.Name == @new.Area).FirstOrDefault(),
                    CreditsCount = @new.CreditsCount
                };
                if (@new.description == null)
                {
                    newMajor.Description = "Pendiente".ToUpper();
                }
                else
                {
                    newMajor.Description = @new.description;
                }

                c.Majors.Add(newMajor);
                c.SaveChanges();
            }
        }