Ejemplo n.º 1
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));
     }
 }
Ejemplo n.º 2
0
 public HttpResponseMessage Register(userDTO id)
 {
     try
     {
         var newUser = new SistemaAcademico.Classes.User
         {
             Email     = id.email,
             Name      = id.Name,
             Name2     = id.Name2,
             BirthDate = id.birthdate,
             PhoneNum  = id.phoneNum,
             LastName  = id.LastName,
             UserType  = id.userType,
             Sex       = id.sex
         };
         SHA512 SHA            = new SHA512Managed();
         string password       = id.password;
         var    password_bytes = ASCIIEncoding.ASCII.GetBytes(password);
         byte[] passBytes      = new byte[password_bytes.Length];
         for (int i = 0; i < password_bytes.Length; i++)
         {
             passBytes[i] = password_bytes[i];
         }
         string hashedPass = Convert.ToBase64String(SHA.ComputeHash(passBytes));
         newUser.Password = hashedPass;
         using (var context = new SistemaAcademico.DataModel.AcademicSystemContext())
         {
             context.Usuarios.Add(newUser);
             context.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Created, newUser.UserId));
         }
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             return(Request.CreateResponse(HttpStatusCode.InternalServerError));
         }
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Ejemplo n.º 3
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();
            }
        }