Пример #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));;
            }
        }
Пример #2
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));;
            }
        }
Пример #3
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));
            }
        }