예제 #1
0
        public IActionResult GetRejection([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var    userCp   = HttpContext.User;
            string landlord = TokenVerifier.GetLandlord(userCp);
            var    property = _context.Property.Where(p => p.ID == id).FirstOrDefault();

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

            List <Rejection> rejection = null;

            if (TokenVerifier.CheckOfficer(userCp) || landlord == property.AppUserRef)
            {
                rejection = _context.
                            Rejection.
                            Where(p => p.ID == id).
                            OrderByDescending(p => p.Timestamp).
                            ToList();
            }
            else
            {
                return(Unauthorized());
            }

            return(Ok(rejection));
        }
예제 #2
0
        public async Task <IActionResult> ApproveProperty([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Check all attributes are there? Will the binding be successful?

            var userCp   = HttpContext.User;
            var property = await _context.Property.FindAsync(id);

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

            if (TokenVerifier.CheckOfficer(userCp))
            {
                property.PropertyStatus = Property.VerificationStatus.Approved;
                property.Timestamp      = DateTime.Now;

                List <Rejection> rejections = _context.Rejection.Where(i => i.PropertyRef == id).ToList();
                foreach (Rejection r in rejections)
                {
                    _context.Rejection.Remove(r);
                }

                await _context.SaveChangesAsync();

                return(Ok());
            }
            return(Unauthorized());
        }
예제 #3
0
        public IActionResult GetPending()
        {
            var userCp = HttpContext.User;

            if (TokenVerifier.CheckOfficer(userCp))
            {
                return(Ok(GetProperties(Property.VerificationStatus.Pending)));
            }
            return(Unauthorized());
        }
예제 #4
0
        public async Task <IActionResult> RejectProperty([FromRoute] int id, [FromBody] BasicRejection addRejection)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Check all attributes are there? Will the binding be successful?

            var userCp   = HttpContext.User;
            var property = await _context.Property.FindAsync(id);

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

            if (TokenVerifier.CheckOfficer(userCp))
            {
                Rejection rejection = _mapper.Map <BasicRejection, Rejection>(addRejection);
                rejection.PropertyRef = id;
                rejection.Timestamp   = DateTime.Now;

                if (!TryValidateModel(rejection))
                {
                    return(BadRequest());
                }

                _context.Rejection.Add(rejection);

                property.PropertyStatus = Property.VerificationStatus.Rejected;
                property.Timestamp      = DateTime.Now;

                await _context.SaveChangesAsync();

                return(Ok());
            }
            return(Unauthorized());
        }