Exemplo n.º 1
0
        public HttpResponseMessage Submit(string From, string To, string Reason)
        {
            DateTime FromDt     = Convert.ToDateTime(From);
            DateTime ToDt       = Convert.ToDateTime(To);
            string   ReasonText = Reason.Trim();
            int      result     = DateTime.Compare(FromDt, ToDt);

            if (result > -1 && result != 0)
            {
                // To date is greater than From
                return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError));
            }
            else
            {
                string Name = User.Identity.Name.Split('\\')[1];;
                using (var db = new LeaveRequestContext())
                {
                    db.LeaveRequest.Add(new LeaveRequest {
                        Name        = Name,
                        From        = FromDt,
                        To          = ToDt,
                        Reason      = ReasonText,
                        Approved    = "NA",
                        Approver    = "NA",
                        RequestTime = DateTime.Now,
                    });
                    var count = db.SaveChanges();
                }
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));;
            }
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            var context = new LeaveRequestContext();
            var models  = context.LeaveRequest.
                          Where(s => s.Approved != "Rejected");

            return(View(models));
        }
Exemplo n.º 3
0
        public IActionResult Approve()
        {
            var userName = User.Identity.Name.Split('\\')[1];
            var context  = new AdminModelContext();
            var admin    = context.AdminModel.Where(s => s.Name == userName);

            if (admin == null)
            {
                return(View("Error"));
            }
            else
            {
                var LeaveContext = new LeaveRequestContext();
                var pending      = LeaveContext.LeaveRequest
                                   .Where(s => s.Approved == "NA");
                return(View(pending));
            }
        }
Exemplo n.º 4
0
        public IActionResult Index()
        {
            try
            {
                var userName = User.Identity.Name.Split('\\')[1];
                _logger.LogInformation("Username", userName);

                var context = new AdminModelContext();
                var IsAdmin = context.AdminModel.Where(s => s.Name == userName);
                if (IsAdmin.Count() == 1)
                {
                    HttpContext.Session.SetString("admin", "true");
                }
                var LeaveContext = new LeaveRequestContext();

                var pendingcount = LeaveContext.LeaveRequest
                                   .Where(o => o.Name == userName)
                                   .Where(o => o.Approved == "NA")
                                   .Count();
                ViewData["pendingcount"] = pendingcount;

                var approvedcount = LeaveContext.LeaveRequest
                                    .Where(o => o.Name == userName)
                                    .Where(o => o.Approved == "Approved")
                                    .Count();
                ViewData["approvedcount"] = approvedcount;

                var rejectedcount = LeaveContext.LeaveRequest
                                    .Where(o => o.Name == userName)
                                    .Where(o => o.Approved == "Rejected")
                                    .Count();
                ViewData["rejectedcount"] = rejectedcount;

                return(View());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(View());
            }
        }
Exemplo n.º 5
0
        public HttpResponseMessage Delete(string sid)
        {
            try
            {
                int    Id   = Convert.ToInt32(sid);
                string Name = User.Identity.Name.Split('\\')[1];;
                using (var db = new LeaveRequestContext())
                {
                    var selected = db.LeaveRequest
                                   .Where(x => x.Id == Id && x.Approved == "NA").First();

                    db.LeaveRequest.Remove(selected);
                    var count = db.SaveChanges();
                }
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));
            }
        }
Exemplo n.º 6
0
        public IActionResult Index()
        {
            var context = new LeaveRequestContext();

            var baseContext = context.LeaveRequest;

            var Approved = baseContext
                           .Where(x => x.Approved == "Approved");

            var Rejected = baseContext
                           .Where(x => x.Approved == "Rejected");


            var Pending = baseContext
                          .Where(x => x.Approved == "NA");
            dynamic model = new ExpandoObject();

            model.Approved = Approved;
            model.Rejected = Rejected;
            model.Pending  = Pending;
            return(View(model));
        }
Exemplo n.º 7
0
        public IActionResult Index()
        {
            var context     = new LeaveRequestContext();
            var userName    = User.Identity.Name.Split('\\')[1];
            var baseContext = context.LeaveRequest
                              .Where(s => s.Name == userName);

            var Approved = baseContext
                           .Where(x => x.Approved == "Approved");

            var Rejected = baseContext
                           .Where(x => x.Approved == "Rejected");


            var Pending = baseContext
                          .Where(x => x.Approved == "NA");

            dynamic model = new ExpandoObject();

            model.Approved = Approved;
            model.Rejected = Rejected;
            model.Pending  = Pending;
            return(View(model));
        }
Exemplo n.º 8
0
        public HttpResponseMessage Approver(string Id, int Approve)
        {
            var context  = new LeaveRequestContext();
            int RealId   = Convert.ToInt32(Id);
            var selected = context.LeaveRequest.Where(s => s.Id == RealId);

            if (selected == null)
            {
                // To date is greater than From
                return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest));;
            }
            else
            {
                if (Approve == 1)
                {
                    foreach (var element in selected)
                    {
                        // This loop should happen only once
                        element.Approved = "Approved";
                        element.Approver = User.Identity.Name.Split('\\')[1];;
                    }
                    context.SaveChanges();
                }
                else if (Approve == 2)
                {
                    foreach (var element in selected)
                    {
                        // This loop should happen only once
                        element.Approved = "Rejected";
                        element.Approver = User.Identity.Name.Split('\\')[1];;
                    }
                    context.SaveChanges();
                }
                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));;
            }
        }