Exemplo n.º 1
0
        public ActionResult SaveWorkspaceOwner(WorkSpaceOwnerModel WorkspaceOwnerdata)
        {
            var loggedinUser = Session["UserName"].ToString();

            WorkSpaceOwnerModel workspaceOwnerModel = new WorkSpaceOwnerModel()
            {
                WorkspaceID  = WorkspaceOwnerdata.WorkspaceID,
                OwnerID      = WorkspaceOwnerdata.OwnerID,
                CreatedDate  = DateTime.Now,
                CreatedBy    = loggedinUser,
                ModifiedDate = DateTime.Now,
                ModifiedBy   = loggedinUser,
                Active       = true
            };

            string Baseurl = ConfigurationManager.AppSettings["baseURL"] + "api/SaveWorkspaceOwner";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //HTTP POST
                var postTask = client.PostAsJsonAsync <WorkSpaceOwnerModel>(Baseurl, workspaceOwnerModel);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
Exemplo n.º 2
0
        //To save role and access rights
        public IHttpActionResult SaveWorkspaceOwner(WorkSpaceOwnerModel workSpaceOwnerModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    WorkSpaceData workSpaceData = new WorkSpaceData();

                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <WorkSpaceOwnerModel, WorkSpaceOwnerDTO>();
                    });
                    IMapper mapper = config.CreateMapper();

                    var workspaceOwner = mapper.Map <WorkSpaceOwnerModel, WorkSpaceOwnerDTO>(workSpaceOwnerModel);

                    workSpaceData.SaveWorkspaceOwner(workspaceOwner);

                    return(Created("api/SaveWorkspaceOwner", true));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Could not save workspace Owner"));
            }
        }
        public ActionResult CreateNewRequest(WorkFlowMasterModel workFlowMasterModel)
        {
            var loggedinUser = Session["UserName"].ToString();

            var treelist = Request.Form["selectedItems"];

            var treeViewModel = JsonConvert.DeserializeObject <List <TreeViewNode> >(treelist);

            List <WorkFlowMasterModel> workFlowMasterList = new List <WorkFlowMasterModel>();

            foreach (var a in treeViewModel)
            {
                if (a.parent == "#")
                {
                    WorkFlowMasterModel workFlowMasterValues = new WorkFlowMasterModel()
                    {
                        WorkspaceID   = a.id,
                        WorkspaceName = a.text,
                        ReportID      = null,
                        ReportName    = null,
                        RequestFor    = loggedinUser,
                        RequestedBy   = loggedinUser,
                        RequestedDate = DateTime.Now,
                        Status        = "PENDING"
                    };
                    workFlowMasterList.Add(workFlowMasterValues);
                }
                else
                {
                    WorkFlowMasterModel workFlowMasterValues = new WorkFlowMasterModel()
                    {
                        WorkspaceID   = a.parent,
                        WorkspaceName = a.parenttext,
                        ReportID      = a.id,
                        ReportName    = a.text,
                        RequestFor    = loggedinUser,
                        RequestedBy   = loggedinUser,
                        RequestedDate = DateTime.Now,
                        Status        = "PENDING"
                    };
                    workFlowMasterList.Add(workFlowMasterValues);
                }
            }

            List <WorkFlowMasterModel> workspaces = new List <WorkFlowMasterModel>();

            for (int i = 0; i < workFlowMasterList.Count; i++)
            {
                bool duplicate = false;
                for (int z = 0; z < i; z++)
                {
                    if (workFlowMasterList[z].WorkspaceID == workFlowMasterList[i].WorkspaceID)
                    {
                        duplicate = true;
                        break;
                    }
                }
                if (!duplicate)
                {
                    List <WorkFlowDetailsModel> workFlowDetailsList = new List <WorkFlowDetailsModel>();
                    foreach (var b in workFlowMasterList)
                    {
                        if (b.ReportID != null && b.WorkspaceID == workFlowMasterList[i].WorkspaceID)
                        {
                            WorkFlowDetailsModel workFlowDetails = new WorkFlowDetailsModel()
                            {
                                ReportID      = b.ReportID,
                                ReportName    = b.ReportName,
                                RequestedDate = b.RequestedDate,
                                Status        = b.Status
                            };
                            workFlowDetailsList.Add(workFlowDetails);
                        }
                    }
                    //to get the workspace owner for a given workspace
                    WorkSpaceOwnerModel workspaceOnwer = new WorkSpaceOwnerModel();
                    string baseurl = ConfigurationManager.AppSettings["baseURL"];
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(baseurl);
                        client.DefaultRequestHeaders.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var responseTask = client.GetAsync(string.Format("api/GetWorkSpaceOwnerByWorkspaceId/?workspaceId={0}", workFlowMasterList[i].WorkspaceID));
                        responseTask.Wait();

                        var result = responseTask.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            var readTask = result.Content.ReadAsAsync <WorkSpaceOwnerDTO>();
                            readTask.Wait();

                            var config = new MapperConfiguration(cfg =>
                            {
                                cfg.CreateMap <WorkSpaceOwnerDTO, WorkSpaceOwnerModel>();
                                cfg.CreateMap <UsersDTO, UsersModel>();
                                cfg.CreateMap <PermissionMasterDTO, PermissionMasterModel>();
                                cfg.CreateMap <UserRoleMappingDTO, UserRoleMappingModel>();
                            });
                            IMapper mapper = config.CreateMapper();

                            workspaceOnwer = mapper.Map <WorkSpaceOwnerDTO, WorkSpaceOwnerModel>(readTask.Result);
                            if (workspaceOnwer == null)
                            {
                                ViewBag.ErrorMessage = "Workspace Owner is not assigned to the workspace " + workFlowMasterList[i].WorkspaceName + ",kindly contact Admin";
                                List <TreeViewNode> nodes = new List <TreeViewNode>();
                                nodes        = (List <TreeViewNode>)Session["Nodes"];
                                ViewBag.Json = (new JavaScriptSerializer()).Serialize(nodes);

                                return(View());
                            }
                        }
                    }

                    WorkFlowMasterModel workFlowModel = new WorkFlowMasterModel()
                    {
                        WorkspaceID     = workFlowMasterList[i].WorkspaceID,
                        WorkspaceName   = workFlowMasterList[i].WorkspaceName,
                        OwnerID         = workspaceOnwer.OwnerID,
                        OwnerEmail      = workspaceOnwer.UserMaster.EmailID,
                        RequestFor      = workFlowMasterList[i].RequestFor,
                        RequestedBy     = workFlowMasterList[i].RequestedBy,
                        RequestedDate   = workFlowMasterList[i].RequestedDate,
                        Status          = workFlowMasterList[i].Status,
                        WorkFlowDetails = workFlowDetailsList
                    };
                    workspaces.Add(workFlowModel);
                }
            }


            string Baseurl = ConfigurationManager.AppSettings["baseURL"] + "api/AddNewRequest";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //HTTP POST
                var postTask = client.PostAsJsonAsync <List <WorkFlowMasterModel> >(Baseurl, workspaces);
                postTask.Wait();
                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var subject = "New request created";
                    var link    = ConfigurationManager.AppSettings["redirectUri"] + "PendingApprovals/ViewPendingApprovals";
                    var body    = "Kindly approve the request by clicking following link.<br>" + "\n\n<a Href= " + link + "> Click here </a>";
                    //send email
                    string baseurl = ConfigurationManager.AppSettings["baseURL"] + "api/SendEmail";
                    foreach (var a in workspaces)
                    {
                        EmailModel emailModel = new EmailModel();
                        emailModel.ToEmail = a.OwnerEmail;
                        emailModel.Subject = subject;
                        emailModel.Body    = body;
                        using (var client1 = new HttpClient())
                        {
                            client1.BaseAddress = new Uri(baseurl);
                            client1.DefaultRequestHeaders.Accept.Clear();
                            client1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                            //HTTP POST
                            var postEmailTask = client1.PostAsJsonAsync <EmailModel>(baseurl, emailModel);
                            postEmailTask.Wait();
                            var emailResult = postEmailTask.Result;
                            if (emailResult.IsSuccessStatusCode)
                            {
                                //return RedirectToAction("CreateNewRequest");
                            }
                        }
                    }
                }
            }

            return(RedirectToAction("CreateNewRequest"));

            //return View();
        }
        public ActionResult RejectRequest(List <TreeViewNode> WorkspaceandReportList, int RequestID)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            var loggedinUser = Session["UserName"].ToString();

            List <WorkFlowMasterModel> workFlowMasterList = new List <WorkFlowMasterModel>();

            foreach (var a in WorkspaceandReportList)
            {
                if (a.parent == "#")
                {
                    WorkFlowMasterModel workFlowMasterValues = new WorkFlowMasterModel()
                    {
                        RequestID     = RequestID,
                        WorkspaceID   = a.id,
                        WorkspaceName = a.text,
                        ReportID      = null,
                        ReportName    = null,
                        ProcessedDate = DateTime.Now,
                        Status        = "REJECTED"
                    };
                    workFlowMasterList.Add(workFlowMasterValues);
                }
                else
                {
                    WorkFlowMasterModel workFlowMasterValues = new WorkFlowMasterModel()
                    {
                        RequestID     = RequestID,
                        WorkspaceID   = a.parent,
                        WorkspaceName = a.parenttext,
                        ReportID      = a.id,
                        ReportName    = a.text,
                        ProcessedDate = DateTime.Now,
                        Status        = "REJECTED"
                    };
                    workFlowMasterList.Add(workFlowMasterValues);
                }
            }


            List <WorkFlowMasterModel> workspaces = new List <WorkFlowMasterModel>();

            for (int i = 0; i < workFlowMasterList.Count; i++)
            {
                bool duplicate = false;
                for (int z = 0; z < i; z++)
                {
                    if (workFlowMasterList[z].WorkspaceID == workFlowMasterList[i].WorkspaceID)
                    {
                        duplicate = true;
                        break;
                    }
                }
                if (!duplicate)
                {
                    List <WorkFlowDetailsModel> workFlowDetailsList = new List <WorkFlowDetailsModel>();
                    foreach (var b in workFlowMasterList)
                    {
                        if (b.ReportID != null && b.WorkspaceID == workFlowMasterList[i].WorkspaceID)
                        {
                            WorkFlowDetailsModel workFlowDetails = new WorkFlowDetailsModel()
                            {
                                RequestID     = b.RequestID,
                                ReportID      = b.ReportID,
                                ReportName    = b.ReportName,
                                ProcessedDate = b.ProcessedDate,
                                Status        = b.Status
                            };
                            workFlowDetailsList.Add(workFlowDetails);
                        }
                    }
                    //to get the workspace owner for a given workspace
                    WorkSpaceOwnerModel workspaceOnwer = new WorkSpaceOwnerModel();
                    string baseurl = ConfigurationManager.AppSettings["baseURL"];
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(baseurl);
                        client.DefaultRequestHeaders.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var responseTask = client.GetAsync(string.Format("api/GetWorkSpaceOwnerByWorkspaceId/?workspaceId={0}", workFlowMasterList[i].WorkspaceID));
                        responseTask.Wait();

                        var result = responseTask.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            var readTask = result.Content.ReadAsAsync <WorkSpaceOwnerDTO>();
                            readTask.Wait();

                            var config = new MapperConfiguration(cfg =>
                            {
                                cfg.CreateMap <WorkSpaceOwnerDTO, WorkSpaceOwnerModel>();
                                cfg.CreateMap <UsersDTO, UsersModel>();
                                cfg.CreateMap <PermissionMasterDTO, PermissionMasterModel>();
                                cfg.CreateMap <UserRoleMappingDTO, UserRoleMappingModel>();
                            });
                            IMapper mapper = config.CreateMapper();

                            workspaceOnwer = mapper.Map <WorkSpaceOwnerDTO, WorkSpaceOwnerModel>(readTask.Result);
                        }
                    }

                    WorkFlowMasterModel workFlowModel = new WorkFlowMasterModel()
                    {
                        RequestID       = workFlowMasterList[i].RequestID,
                        WorkspaceID     = workFlowMasterList[i].WorkspaceID,
                        WorkspaceName   = workFlowMasterList[i].WorkspaceName,
                        OwnerID         = workspaceOnwer.OwnerID,
                        ProcessedDate   = workFlowMasterList[i].ProcessedDate,
                        Status          = workFlowMasterList[i].Status,
                        WorkFlowDetails = workFlowDetailsList
                    };
                    workspaces.Add(workFlowModel);
                }
            }


            string Baseurl = ConfigurationManager.AppSettings["baseURL"] + "api/RejectRequest";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Baseurl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //HTTP POST
                var postTask = client.PostAsJsonAsync <List <WorkFlowMasterModel> >(Baseurl, workspaces);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("ViewPendingApprovals"));
                }
            }
            return(View());
        }