public ActionResult UpdateUser(UserViewModel model, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file != null && file.ContentLength > 0)
         {
             CommonController common = new CommonController();
             model.User.photo = Path.GetFileName(file.FileName);
             string filePath = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["FilePath"].ToString()), Path.GetFileName(file.FileName));
             string message  = common.UploadFile(file, filePath);
             ModelState.AddModelError("User.Photo", message);
         }
         UserService.UserServiceClient Client = new UserService.UserServiceClient();
         model.User.IsActive = true;
         Client.updateUser(model.User);
         Client.UpdateUserGroupMember(model.User.UserId);
         Client.insertUserGroupmember(model.User.UserId, model.UserGroupID);
         Client.UpdateUserRole(model.User.UserId);
         Client.insertUserRole(model.User.UserId, model.RoleID);
         return(View("ListofUsers"));
     }
     else
     {
         ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
     }
     return(View("ListofUsers"));
 }
        public ActionResult AddUser(UserViewModel model, HttpPostedFileBase file)
        {
            UserService.UserServiceClient Client = new UserService.UserServiceClient();
            model.User.Company_Id = Convert.ToInt32(Session["GroupCompanyId"]);
            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    CommonController common = new CommonController();
                    model.User.photo = Path.GetFileName(file.FileName);
                    string filePath = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["FilePath"].ToString()), Path.GetFileName(file.FileName));
                    string message  = common.UploadFile(file, filePath);
                    //ModelState.AddModelError("User.Photo", message);
                }
                string res = Client.insertUser(model.User);
                if (res != "EXISTS")
                {
                    model.User.UserId = Convert.ToInt32(res);
                    Client.insertUserGroupmember(model.User.UserId, model.UserGroupID);
                    //Client.insertUserRole(model.User.UserId, model.RoleID);
                    TempData["Message"] = "Successfully created" + model.User.FirstName;
                    return(RedirectToAction("ListofUsers"));
                }
                else
                {
                    ModelState.AddModelError("User.EmailId", "UserName is already Exists");
                }
            }
            else
            {
                ModelState.AddModelError("", ConfigurationManager.AppSettings["Requried"]);
            }
            model.User.UserId   = 0;
            model.UserGroupList = (List <SelectListItem>)TempData["UserGroup"];
            //string xmlGroups = Client.GetUserGroup(0);
            //DataSet Groups = new DataSet();
            //Groups.ReadXml(new StringReader(xmlGroups));
            //model.UserGroupList = new List<SelectListItem>();
            //foreach (System.Data.DataRow row in Groups.Tables[0].Rows)
            //{
            //    model.UserGroupList.Add(new SelectListItem { Text = row["User_Group_Name"].ToString(), Value = row["User_Group_ID"].ToString() });
            //}
            //string xmlRoles = Client.GetRoles(0);
            //DataSet dsRoles = new DataSet();
            //dsRoles.ReadXml(new StringReader(xmlRoles));
            //model.RolesList = new List<SelectListItem>();
            //foreach (System.Data.DataRow row in dsRoles.Tables[0].Rows)
            //{
            //    model.RolesList.Add(new SelectListItem { Text = row["Role_Name"].ToString(), Value = row["Role_ID"].ToString() });
            //}

            return(View("_AddUser", model));
        }
        public ActionResult addComplianceAudit(FormCollection formCollection, HttpPostedFileBase file, string submit)
        {
            if (ModelState.IsValid)
            {
                //AuditViewModel auditViewModel = new AuditViewModel();
                //auditViewModel.complianceAudit = new ComplianceAudit();
                //for(int i =0; i< formCollection.Count; i++ )
                //{
                //    var str = formCollection["complianceAuditList[1].Audit_Status"];
                //}

                //DataTable dt = new DataTable();
                //DataSet ds = new DataSet();
                int counter = 0;
                List <ComplianceAudit> auditdata = new List <ComplianceAudit>();
                ComplianceAudit        audit     = null;
                //foreach(var item in formCollection)
                //{
                //}
                int    key = formCollection.Count;
                string str = Convert.ToString(key - 1);

                int rulecount = Convert.ToInt32(Session["rulecount"]);
                //  int rulecount1 = Convert.ToInt32(formCollection[str]);
                for (int index = 0; index < rulecount; index++)

                //{
                //    if (formCollection[index].ToString().Contains("complianceAuditList"))
                {
                    //if (formCollection[index].Contains("complianceAuditList"))
                    //{
                    audit = new ComplianceAudit();
                    AuditViewModel auditm = new AuditViewModel();
                    auditm.complianceAudit = new ComplianceAudit();
                    //string str = formCollection["complianceAuditList["+ counter + "].Audit_Status"];
                    // auditm.complianceAudit.Audit_Status = formCollection["complianceAuditList[" + counter + "].Audit_Status"];
                    audit.Audit_Status       = formCollection["complianceAuditList[" + index + "].Audit_Status"];
                    audit.Audit_Date         = Convert.ToDateTime(formCollection["complianceAuditList[" + index + "].Audit_Date"]);
                    audit.Audit_Remarks      = formCollection["complianceAuditList[" + index + "].Audit_Remarks"];
                    audit.Penalty_nc         = formCollection["complianceAuditList[" + index + "].Penalty_nc"];
                    audit.Compliance_Xref_Id = Convert.ToInt32(formCollection["complianceAuditList[" + index + "].Compliance_Xref_ID"]);
                    audit.Auditor_Id         = Convert.ToInt32(Session["AuditorID"]);//1;// Convert.ToInt32(formCollection["complianceAuditList[" + counter + "].Auditor_ID"]);
                    if (file != null)
                    {
                        CommonController common = new CommonController();
                        audit.Audit_ArteFacts = Path.GetFileName(file.FileName);
                        string filePath = Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["FilePath"].ToString()), Path.GetFileName(file.FileName));
                        string message  = common.UploadFile(file, filePath);
                        // ModelState.AddModelError("org_hier.logo", message);
                    }

                    audit.Audit_ArteFacts     = formCollection["complianceAuditList[" + index + "].Audit_ArteFacts"];
                    audit.Compliance_Audit_Id = Convert.ToInt32(formCollection["complianceAuditList[" + index + "].Compliance_Audit_Id"]);
                    // audit.Compliance_Options_Id = 1;// Convert.ToInt32(formCollection["complianceAuditList[" + counter + "].Compliance_Options_Id"]);
                    audit.Compliance_Schedule_Instance = Convert.ToInt32(formCollection["complianceAuditList[" + index + "].Compliance_Schedule_Instance"]);
                    // audit.Is_Active = Convert.ToBoolean(formCollection["complianceAuditList[" + counter + "].Compliance_Schedule_Instance"]);
                    //audit.Last_Update_dDate = Convert.ToDateTime(formCollection["complianceAuditList[" + counter + "].Compliance_Schedule_Instance"]);
                    audit.Org_Hier_Id       = Convert.ToInt32(Session["ComplianceBranchID"]);// 17; // Convert.ToInt32(formCollection["complianceAuditList[" + counter + "].Compliance_Schedule_Instance"]);
                    audit.Reviewer_Comments = formCollection["complianceAuditList[" + index + "].Compliance_Schedule_Instance"];
                    audit.Reviewer_Id       = Convert.ToInt32(formCollection["complianceAuditList[" + index + "].Compliance_Schedule_Instance"]);
                    audit.User_Id           = 1;    // Convert.ToInt32(formCollection["complianceAuditList[" + counter + "].Compliance_Schedule_Instance"]);
                    audit.Is_Active         = true; //formCollection["complianceAuditList[" + index + "].Is_Active"];
                    audit.Version           = Convert.ToInt32(formCollection["complianceAuditList[" + index + "].Compliance_Schedule_Instance"]);

                    switch (submit)
                    {
                    case "Save as Draft":
                        audit.Version   = 0;
                        ViewBag.Message = "Saved as draft";

                        break;

                    case "Submit":
                        audit.Version   = 1;
                        ViewBag.Message = "Subitted successfully";
                        break;
                    }

                    auditdata.Add(audit);

                    //counter++;

                    //}
                }
                bool result = false;
                AuditService.AuditServiceClient auditServiceClient = new AuditService.AuditServiceClient();
                string compliancedata = Convert.ToString(auditServiceClient.insertComplianceAudit(auditdata.ToArray()));
                if (compliancedata != null)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(View("View"));
        }