示例#1
0
        // PUT api/TestDept/5
        public HttpResponseMessage Putdepartment(string id, department department)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != department.code)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage PostNewRequest(RequestsWtihLinkedData rwld)
        {
            if (ModelState.IsValid)
            {
                var newReq = SetupNewRequestObject(rwld, true);

                _db.requests.Add(newReq);

                _db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, newReq);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = newReq.id }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
示例#3
0
        public HttpResponseMessage PostChangePassword(Models.PasswordModel pm)
        {
            Authentication auth = new Authentication();

            string deptCode = GetAuthorisedDepartment().code;

            bool correctPassword = auth.ValidateUser(deptCode, pm.currentPassword);

            if (correctPassword)
            {
                if (ModelState.IsValid)
                {
                    department dept =
                        (from d in _db.departments
                         where d.code == deptCode
                         select d).FirstOrDefault();

                    string deptSalt = dept.salt;

                    string newDeptPassword = auth.HashPassword(pm.newPassword, deptSalt);

                    dept.hashedPassword = newDeptPassword;

                    _db.Entry(dept).CurrentValues.SetValues(dept);

                    _db.SaveChanges();

                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, pm);
                    response.Headers.Location = new Uri(Url.Link("DefaultApi", null));
                    return(response);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.OK, "Invalid Password"));
            }
        }
        public ActionResult SetupUsers()
        {
            using (var _db = new TimetablingSystemContext())
            {

                var deptList = _db.departments;

                foreach (DBInterface.department dept in deptList)
                {

                    dept.salt = auth.GenerateSalt();
                    dept.hashedPassword = auth.HashPassword("w6vnh4n", dept.salt);

                }

                _db.SaveChanges();

            }

            return Content("All users returned to default password");
        }