示例#1
0
        /// <summary>
        /// Update the status of an approval
        /// </summary>
        /// <param name="id"></param>
        /// <param name="appr"></param>
        /// <returns></returns>
        public HttpResponseMessage Put(int id, [FromBody] approval appr)
        {
            try
            {
                using (ebuilderEntities entities = new ebuilderEntities())
                {
                    var entity = entities.approvals.FirstOrDefault(a => a.APID == id);

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Approval with APID " + id.ToString() + " not found"));
                    }
                    else
                    {
                        entity.status = appr.status.ToLower();
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> Edit(approval newApproval)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/Json"));

                //Convert the edited approval object json
                var json = JsonConvert.SerializeObject(newApproval);

                //creates a stringcontent object to pass to api, which is derived from httpcontent class
                var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

                //call the api
                var response = await client.PutAsync("Approvals/" + newApproval.APID.ToString(), stringContent);

                //check whether it was successfully updated
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    //alert to be displayed
                    ViewBag.Message = "Update Successful";
                }
                else
                {
                    //alert to be dispalyed
                    ViewBag.Message = response.Content.ReadAsStringAsync().Result.ToString();
                }
                return(View());
            }
        }
示例#3
0
        /// <summary>
        /// Add an approval
        /// </summary>
        /// <param name="appr"></param>
        /// <returns></returns>
        public HttpResponseMessage Post([FromBody] approval appr)
        {
            try
            {
                using (ebuilderEntities entities = new ebuilderEntities())
                {
                    var entity = entities.approvals.FirstOrDefault(a => a.ManagerID == appr.ManagerID && a.LID == appr.LID);
                    if (entity != null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Approval already available with given datails"));
                    }

                    appr.status = "pending";
                    entities.approvals.Add(appr);
                    entities.SaveChanges();
                    var message = Request.CreateResponse(HttpStatusCode.OK, appr);
                    message.Headers.Location = new Uri(Request.RequestUri + appr.APID.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                approval anEntity       = null;
                Int32    loggedInUserId = 0;

                if (id <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                var loggedInMember = LoggedInUser();
                loggedInUserId = loggedInMember.member_id;

                //fetch the object to be updated (assuming that it exists)
                anEntity = await agent.Find <approval>(id);

                if (anEntity == null)
                {
                    return(new NotFoundResult());
                }

                //remove id from HWM or DF
                if (anEntity.hwms.Count > 0)
                {
                    anEntity.hwms.ToList().ForEach(x =>
                    {
                        x.approval_id = null;
                        // last updated parts
                        x.last_updated    = DateTime.Now;
                        x.last_updated_by = loggedInUserId;
                        agent.Update <hwm>(x.hwm_id, x);
                    });
                }
                if (anEntity.data_file.Count > 0)
                {
                    anEntity.data_file.ToList().ForEach(x =>
                    {
                        x.approval_id     = null;
                        x.last_updated    = DateTime.Now;
                        x.last_updated_by = loggedInUserId;
                        agent.Update <data_file>(x.data_file_id, x);
                    });
                }
                //delete it
                await agent.Delete <approval>(anEntity);

                //sm(agent.Messages);

                return(Ok());
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
        public async Task <IActionResult> ApproveNWISDataFile(int dataFileId)
        {
            try
            {
                data_file aDataFile      = null;
                approval  anEntity       = null;
                Int32     loggedInUserId = 0;

                if (dataFileId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                anEntity = new approval();

                //get logged in user
                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                loggedInUserId = loggedInMember.member_id;

                aDataFile = agent.Select <data_file>().Include(d => d.instrument).FirstOrDefault(d => d.data_file_id == dataFileId);
                if (aDataFile == null)
                {
                    return(new BadRequestObjectResult("invalid data file id"));
                }

                //get event coordinator to set as approver for NWIS datafile

                members eventCoor = agent.Select <members>().Include(m => m.events).FirstOrDefault(m => m.events.Any(e => e.event_id == aDataFile.instrument.event_id));
                if (eventCoor == null)
                {
                    return(new BadRequestObjectResult("invalid input parameters"));
                }

                //set time and user of approval
                anEntity.approval_date = DateTime.UtcNow;
                anEntity.member_id     = eventCoor.member_id;
                anEntity = await agent.Add <approval>(anEntity);

                //set datafile approvalID
                aDataFile.approval_id     = anEntity.approval_id;
                aDataFile.last_updated    = DateTime.Now;
                aDataFile.last_updated_by = loggedInUserId;

                await agent.Update <data_file>(aDataFile.data_file_id, aDataFile);

                //sm(agent.Messages);
                return(Ok(anEntity));
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
        public async Task <IActionResult> ApproveHWM(int hwmId)
        {
            try
            {
                hwm      aHWM           = null;
                approval anEntity       = null;
                Int32    loggedInUserId = 0;

                if (hwmId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                anEntity = new approval();
                aHWM     = await agent.Find <hwm>(hwmId);

                if (aHWM == null)
                {
                    return(new BadRequestObjectResult("Invalid hwm id"));
                }

                //get logged in user
                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                loggedInUserId = loggedInMember.member_id;

                //set time and user of approval
                anEntity.approval_date = DateTime.UtcNow;
                anEntity.member_id     = loggedInMember.member_id;

                anEntity = await agent.Add <approval>(anEntity);

                //set HWM approvalID
                aHWM.approval_id = anEntity.approval_id;

                // last updated parts
                aHWM.last_updated    = DateTime.Now;
                aHWM.last_updated_by = loggedInUserId;
                await agent.Update <hwm>(aHWM.hwm_id, aHWM);

                //sm(agent.Messages);
                return(Ok(anEntity));
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
        public async Task <IActionResult> ApproveDataFile(int dataFileId)
        {
            try
            {
                data_file aDataFile      = null;
                approval  anEntity       = null;
                Int32     loggedInUserId = 0;

                if (dataFileId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                anEntity = new approval();

                //get logged in user
                var loggedInMember = LoggedInUser();
                if (loggedInMember == null)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }
                loggedInUserId = loggedInMember.member_id;

                aDataFile = await agent.Find <data_file>(dataFileId);

                if (aDataFile == null)
                {
                    return(new BadRequestObjectResult("invalid data file id"));
                }

                //set time and user of approval
                anEntity.approval_date = DateTime.UtcNow;
                anEntity.member_id     = loggedInUserId;
                anEntity = await agent.Add <approval>(anEntity);

                //set datafile approvalID
                aDataFile.approval_id = anEntity.approval_id;
                // last_update parts
                aDataFile.last_updated    = DateTime.Now;
                aDataFile.last_updated_by = loggedInUserId;
                await agent.Update <data_file>(aDataFile.data_file_id, aDataFile);

                //sm(agent.Messages);
                return(Ok(anEntity));
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
        public async Task <IActionResult> UnApproveDataFile(int dataFileId)
        {
            try
            {
                data_file aDataFile      = null;
                Int32     loggedInUserId = 0;

                //Return BadRequest if missing required fields
                if (dataFileId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                var loggedInMember = LoggedInUser();
                loggedInUserId = loggedInMember.member_id;

                //fetch the object to be updated (assuming that it exists)
                aDataFile = await agent.Find <data_file>(dataFileId);

                if (aDataFile == null)
                {
                    return(new BadRequestObjectResult("invalid data file id"));
                }

                Int32 apprId = aDataFile.approval_id.HasValue ? aDataFile.approval_id.Value : 0;
                //remove id from hwm
                aDataFile.approval_id     = null;
                aDataFile.last_updated    = DateTime.Now;
                aDataFile.last_updated_by = loggedInUserId;
                await agent.Update <data_file>(aDataFile.data_file_id, aDataFile);

                approval anApproval = await agent.Find <approval>(apprId);

                //remove approval
                await agent.Delete <approval>(anApproval);

                //sm(agent.Messages);

                return(Ok());
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
        public async Task <IActionResult> UnApproveHWM(int hwmId)
        {
            try
            {
                hwm aHWM = null;
                //Return BadRequest if missing required fields
                if (hwmId <= 0)
                {
                    return(new BadRequestObjectResult("Invalid input parameters"));
                }

                //fetch the object to be updated (assuming that it exists)
                aHWM = await agent.Find <hwm>(hwmId);

                if (aHWM == null)
                {
                    return(new BadRequestObjectResult("invalid hwm id"));
                }

                Int32 apprId = aHWM.approval_id.HasValue ? aHWM.approval_id.Value : 0;

                //remove id from hwm
                aHWM.approval_id = null;

                // last updated parts
                var   loggedInMember = LoggedInUser();
                Int32 loggedInUserId = loggedInMember.member_id;
                aHWM.last_updated    = DateTime.Now;
                aHWM.last_updated_by = loggedInUserId;
                await agent.Update <hwm>(aHWM.hwm_id, aHWM);

                approval anApproval = await agent.Find <approval>(apprId);

                //remove approval
                await agent.Delete <approval>(anApproval);

                //sm(agent.Messages);

                return(Ok());
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
示例#10
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                if (id < 1)
                {
                    return(new BadRequestResult());
                }
                var entity = await agent.Find <hwm>(id);

                if (entity == null)
                {
                    return(new NotFoundResult());
                }

                //Cascade delete
                var approvalID = entity.approval_id;

                //remove files
                //TODO___ entity.files.ToList().ForEach(f => agent.RemoveFileItem(f));
                if (entity.files != null)
                {
                    entity.files.ToList().ForEach(f => agent.Delete <file>(f));
                }

                //delete HWM now
                await agent.Delete <hwm>(entity);

                if (approvalID.HasValue)
                {
                    approval item = await agent.Find <approval>(approvalID.Value);

                    await agent.Delete <approval>(item);
                }

                //sm(agent.Messages);
                return(Ok());
            }
            catch (Exception ex)
            {
                //sm(agent.Messages);
                return(await HandleExceptionAsync(ex));
            }
        }
示例#11
0
        public approvalView(approval app)
        {
            using (ebuilderEntities entities = new ebuilderEntities())
            {
                this.LID       = app.LID;
                this.APID      = app.APID;
                this.ManagerID = app.ManagerID;
                this.status    = app.status;


                var leave = entities.leavs.FirstOrDefault(l => l.LID == this.LID);
                this.leaveCategory = leave.leaveCategory;
                this.reason        = leave.reason;
                this.date          = leave.date;

                var emp = entities.employees.FirstOrDefault(e => e.EID == leave.EID);
                this.EID   = emp.EID;
                this.fName = emp.fName;
                this.lName = emp.lName;
            }
        }
        public ActionResult Edit(int id, LeaveManagementSystemValueCreed.Models.Leave leaf)
        {
            try
            {
                VC_LMSEntities h            = new VC_LMSEntities();
                var            approval_row = h.approvals.Where(r => r.Leave_id == leaf.ID && r.status == "Approved By HR").FirstOrDefault();
                if (approval_row != null)
                {
                    if (leaf.Status == "Approved")
                    {
                        leaf.Status         = "Cancellation Pending on HR";
                        h.Entry(leaf).State = System.Data.Entity.EntityState.Modified;
                        h.SaveChanges();
                        return(RedirectToAction("Index", "Approver"));
                    }
                }


                int c = 0;
                int e = 0;
                if (leaf.Status == "Approved")
                {
                    c++;
                }
                VC_LMSEntities d   = new VC_LMSEntities();
                var            hr1 = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id).FirstOrDefault();
                if (leaf.Status == "Approved" && hr1.ROLES == "HR")
                {
                    approval approval2 = new approval();
                    approval2.Aprrover_id = Session["userID"].ToString();
                    approval2.Employee_id = leaf.Employee_Id;
                    approval2.Leave_id    = leaf.ID;
                    approval2.status      = "Approved By  " + Session["Name"].ToString();
                    d.approvals.Add(approval2);

                    leaf.Status         = "Approved";
                    hr1.leaves_alloted  = hr1.leaves_alloted - leaf.Number_of_Days;
                    d.Entry(leaf).State = System.Data.Entity.EntityState.Modified;
                    d.Entry(hr1).State  = System.Data.Entity.EntityState.Modified;
                    d.SaveChanges();
                    return(RedirectToAction("Index", "Approver"));
                }
                foreach (var item in d.approvals)
                {
                    if (item.Leave_id == leaf.ID)
                    {
                        c++;
                    }
                }
                if (leaf.Status == "Approved")
                {
                    var i = leaf.Employee_Id;
                    foreach (var item in d.approvers)
                    {
                        if (item.Emplyoee_id == leaf.Employee_Id)
                        {
                            e++;
                        }
                    }
                    if (c == e)
                    {
                        leaf.Status = "Approved By All Approvers";
                        var hr = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id && x.ROLES == "HR").FirstOrDefault();
                        if (hr != null)
                        {
                            hr.leaves_alloted = hr.leaves_alloted - leaf.Number_of_Days;
                            d.Entry(hr).State = System.Data.Entity.EntityState.Modified;
                            approval approval2 = new approval();
                            approval2.Aprrover_id = Session["userID"].ToString();
                            approval2.Employee_id = leaf.Employee_Id;
                            approval2.Leave_id    = leaf.ID;
                            approval2.status      = "Approved By  " + Session["Name"].ToString();
                            d.approvals.Add(approval2);
                            d.SaveChanges();
                        }
                        var emp  = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id).FirstOrDefault();
                        var body = "Hello " + emp.FIRST_NAME + ",< br /> <br /> your Leave has been approved by all the Approvers. <br /> <br /> Warm Regards, <br /> LMS Team.";
                        SendverificationLinkEmail(emp.EMAIL, body);
                        var hrmail = d.UsersTables.Where(x => x.ROLES == "HR").FirstOrDefault();
                        body = "Hello  " + hrmail.FIRST_NAME + ",< br /> <br /> Leave application of  " + leaf.Employe_name + "  has been approved by all approvers and now it is pending on you. <br/> <br /> Warm Regards, <br /> LMS Team.";
                        //SendverificationLinkEmail(hrmail.EMAIL, body);
                        approval approval1 = new approval();
                        approval1.Aprrover_id = Session["userID"].ToString();
                        approval1.Employee_id = leaf.Employee_Id;
                        approval1.Leave_id    = leaf.ID;
                        approval1.status      = "Approved By  " + Session["Name"].ToString();
                        d.approvals.Add(approval1);
                        d.SaveChanges();
                    }
                    else
                    {
                        var emp = d.UsersTables.Where(x => x.EMPLOYEE_ID == leaf.Employee_Id).FirstOrDefault();

                        var body = "Hello " + emp.FIRST_NAME + ",< br /> <br />  your Leave has been approved by  " + Session["userName"] + "< br /> <br /> Warm Regards, <br /> LMS Team.";
                        //SendverificationLinkEmail(emp.EMAIL, body);
                        leaf.Status = "Pending on Approvers";
                        approval approval1 = new approval();
                        approval1.Aprrover_id = Session["userID"].ToString();
                        approval1.Employee_id = leaf.Employee_Id;
                        approval1.Leave_id    = leaf.ID;
                        approval1.status      = "Approved By  " + Session["Name"].ToString();
                        d.approvals.Add(approval1);
                        d.SaveChanges();
                    }
                }
                else if (leaf.Status == "Rejected By Approver")
                {
                    approval approval1 = new approval();
                    approval1.Aprrover_id = Session["userID"].ToString();
                    approval1.Employee_id = leaf.Employee_Id;
                    approval1.Leave_id    = leaf.ID;
                    approval1.status      = "Rejected By  " + Session["Name"].ToString();
                    d.approvals.Add(approval1);
                    d.SaveChanges();
                }
                d.Entry(leaf).State = System.Data.Entity.EntityState.Modified;
                d.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Unable to change the status";
                return(View());
            }
        }
示例#13
0
        /// <summary>
        /// Add a leave for a future date in normal way
        /// </summary>
        /// <param name="leave"></param>
        /// <returns></returns>
        public HttpResponseMessage Post([FromBody] leav leave)
        {
            try
            {
                using (ebuilderEntities entities = new ebuilderEntities())
                {
                    if (DateTime.Compare(leave.date, DateTime.Today) < 0)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid field date"));
                    }


                    //check whether a leave exists for the given day for the employee
                    var entity = entities.leavs.FirstOrDefault(l => l.EID == leave.EID && l.date == leave.date);

                    if (entity != null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Leave Already exists"));
                    }


                    leave.jobCategory = entities.employees.FirstOrDefault(e => e.EID == leave.EID).jobCategory;

                    //Check whether the leaveCategory exists
                    var maxLeaves = entities.leave_type.FirstOrDefault(lt => lt.leaveCategory == leave.leaveCategory && lt.jobCategory == leave.jobCategory).maxAllowed;
                    if (maxLeaves == 0)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Incompatible leave type"));
                    }

                    //check whether the maximum allowed leaves for the period has been taken
                    var leavesTaken = entities.leavs.Where(l => l.EID == leave.EID && l.leaveCategory == leave.leaveCategory && l.date.Year == leave.date.Year).Count();
                    if (leavesTaken >= maxLeaves)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No leaves available"));
                    }

                    leave.leaveCategory = leave.leaveCategory.ToLower();
                    entities.leavs.Add(leave);
                    var man = entities.employees.FirstOrDefault(e => e.EID == leave.EID);

                    entities.Entry(man).Collection("employees").Load();
                    if (man.employees.Any())
                    {
                        foreach (var m in man.employees)
                        {
                            approval app = new approval();
                            app.ManagerID = m.EID;
                            app.LID       = leave.LID;
                            app.status    = "pending";
                            entities.approvals.Add(app);
                        }
                        var message = Request.CreateResponse(HttpStatusCode.OK, leave);
                        entities.SaveChanges();
                        message.Headers.Location = new Uri(Request.RequestUri + leave.LID.ToString());
                        return(message);
                    }
                    else if (leave.jobCategory == "HR Admin")
                    {
                        var message = Request.CreateResponse(HttpStatusCode.OK, leave);
                        entities.SaveChanges();
                        message.Headers.Location = new Uri(Request.RequestUri + leave.LID.ToString());
                        return(message);
                    }
                    else
                    {
                        var message = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occured");
                        return(message);
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }