public ActionResult Create(RequestsModel RequestsObj)
 {
     //------------------------------------------
     //Check ModelState
     //------------------------------------------
     if (!ModelState.IsValid)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Invalid data"));
     }
     //------------------------------------------
     try
     {
         bool result = RequestsFactor.Create(RequestsObj);
         if (result == true)
         {
             return(List(1, 25, null, null, null, null));
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Saving operation faild"));
         }
     }
     catch (Exception ex)
     { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); }
 }
        public async Task <IActionResult> Edit(int id, [Bind("Id,DateSent,UserId,FromDate,UntilDate,LeaveId,HalfDay,AttachmentUrl,Approved")] RequestsModel requestsModel)
        {
            if (id != requestsModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(requestsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RequestsModelExists(requestsModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(requestsModel));
        }
Ejemplo n.º 3
0
        public IActionResult RequestAccepted([FromBody] RequestsModel model)
        {
            var request = _repoWrapper.Requests.GetSingle(r => r.Id == model.Id);

            //var accepted = model.AcceptRequest;
            //if (!accepted)
            //{
            //    return BadRequest();
            //}
            _repoWrapper.Accepted.RequestAccepted(new AcceptedRequests
            {
                Priority  = 3,
                Request   = request,
                RequestID = request.Id
            });
            //_repoWrapper.Requests.UpdateRequest(request);

            _repoWrapper.Save();
            return(Created($"api/requests/{ model.Id}", model));
            //var acceptedId = Guid.NewGuid().ToString();
            //var acceptedRequest = new AcceptedRequests
            //{
            //    AcceptedId = acceptedId,
            //    Priority = 3,
            //    Request = model
            //};
        }
Ejemplo n.º 4
0
        public static bool MakeRequest(RequestsModel myRequest)
        {
            myRequest.requestedById = HttpContext.Current.Session["UserId"].ToString();
            RequestsModel requestModel = new RequestsModel();

            return(requestModel.MakeRequest(myRequest));
        }
        public async Task <IActionResult> Create([Bind("Id,DateSent,UserId,FromDate,UntilDate,LeaveId,HalfDay,AttachmentUrl,Approved")] RequestsModel requestsModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(requestsModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(requestsModel));
        }
        public static int CreateRequest(int id, int userid, string request)
        {
            db = new Database();
            RequestsModel data = new RequestsModel()
            {
                UserId  = userid,
                Request = request,
            };

            return(RequestsDao.Insert(db, data));
        }
Ejemplo n.º 7
0
        private RequestsModel GetRequests(int id)
        {
            RequestsModel output = new RequestsModel();

            output.reqid       = id;
            output.description = GetRandomItem(RequestDescription);
            output.status      = GetRandomItem(RequestStatus);
            output.type        = GetRandomItem(RequestsTypes);
            output.date        = GetRandomDate();

            return(output);
        }
Ejemplo n.º 8
0
        public static int Insert(Database db, RequestsModel orders)
        {
            db.Connect();

            SqlCommand command = db.CreateCommand(SQL_INSERT);

            PrepareCommand(command, orders);

            int ret = db.ExecuteNonQuery(command);

            db.Close();

            return(ret);
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> JobDetails(string id)
        {
            if (!id.IsNullOrWhiteSpace())
            {
                String url     = $"https://jobs.github.com/positions/{id}.json";
                String results = await RequestsModel.GetRequest(url);

                ResultModel resultModel = JsonConvert.DeserializeObject <ResultModel>(results);

                return(View(resultModel));
            }

            return(RedirectToAction("Search"));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> SearchResults(string description, string location)
        {
            if (description.IsNullOrWhiteSpace())
            {
                return(RedirectToAction("Search"));
            }

            String url     = $"https://jobs.github.com/positions.json?description={description}&page=0";
            String results = await RequestsModel.GetRequest(url);

            List <ResultModel> resultsModel = JsonConvert.DeserializeObject <List <ResultModel> >(results);

            return(View(resultsModel));
        }
Ejemplo n.º 11
0
        private static Collection <RequestsModel> Read(SqlDataReader reader)
        {
            Collection <RequestsModel> requests = new Collection <RequestsModel>();

            while (reader.Read())
            {
                int           i       = -1;
                RequestsModel request = new RequestsModel();
                request.Id      = reader.GetInt32(++i);
                request.UserId  = reader.GetInt32(++i);
                request.Request = reader.GetString(++i);
                requests.Add(request);
            }
            return(requests);
        }
Ejemplo n.º 12
0
        public IActionResult Post([FromBody] RequestsModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime d         = DateTime.UtcNow;
            var      principal = HttpContext.User.Identity as ClaimsIdentity;

            model.UserId      = principal.Claims.SingleOrDefault(u => u.Type == "uid")?.Value;
            model.DateCreated = d;
            _repoWrapper.Requests.CreateRequest(model);
            _repoWrapper.Save();
            return(Created($"api/requests/{model.Id}", model));
            //return CreatedAtAction("RequestById", new { id = model.Id }, model);
        }
 public ActionResult GetObject(int id)
 {
     try
     {
         RequestsModel RequestsObj = RequestsFactor.GetObject(id);
         if (RequestsObj == null)
         {
             RequestsObj = new RequestsModel();
         }
         return(Json(RequestsObj, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Ejemplo n.º 14
0
 public int Post([FromBody] RequestsModel model)
 {
     return(RequestsProcessor.CreateRequest(model.Id, model.UserId, model.Request));
 }
Ejemplo n.º 15
0
 private static void PrepareCommand(SqlCommand command, RequestsModel r)
 {
     command.Parameters.AddWithValue("@UserId", r.UserId);
     command.Parameters.AddWithValue("@Request", r.Request);
 }
Ejemplo n.º 16
0
        public static bool RespondToRequest(RequestsModel requestResponse)
        {
            RequestsModel requestModel = new RequestsModel();

            return(requestModel.RespondToRequest(requestResponse));
        }
Ejemplo n.º 17
0
        public static List <RequestsModel> RequestListForOffer(string offerId, int startValue, int noOfRows)
        {
            RequestsModel reqModel = new RequestsModel();

            return(reqModel.ListRequests(offerId, startValue, noOfRows));
        }