예제 #1
0
        /// <summary>
        /// Insert Employee Details
        /// </summary>
        /// <param name="lstEmployeedetails"></param>
        /// <returns></returns>
        public string CreatNewUser(List <MVCModels.User_Employeedetails> lstEmployeedetails, List <MVCModels.User_LeaveTypeModel> lstLeavedetails, List <MVCModels.User_ProductModel> lstProductdetails, List <MVCModels.User_NoticeBoard> lstNoticeboarddetails, List <MVCModels.Splash> lstsplashdetails, List <MVCModels.Edetailing> lstEdetailingDetails, string createdBy, int value, int TPLockvalue, string underuser, int SPLASHID, int EdetailingId, int DACode, string strGuid, string daCode)
        {
            string result = string.Empty;

            _objDALUsercretion = new DAL_UsercreationWizard();

            string divisionCode = lstEmployeedetails[0].Division_Code;
            string projectCode = lstEmployeedetails[0].Project_Code;
            string effectiveFromdate = lstEmployeedetails[0].Effective_From;
            int    InsertDivisionCount = 1, InsertUserProjectCount = 1;

            if (lstEmployeedetails != null && lstEmployeedetails.Count > 0)
            {
                string companyCode       = lstEmployeedetails[0].Company_Code;
                string employeeEntrymode = lstEmployeedetails[0].Entry_Mode;
                result = _objDALUsercretion.InsertEmployeedetails(lstEmployeedetails);


                if (result.Split(':')[0].ToUpper() == "SUCCESS")
                {
                    string employeeCode = result.Split(':')[1];
                    lstEmployeedetails.ForEach
                    (
                        y => y.Employee_Code = employeeCode
                    );

                    result = _objDALUsercretion.InsertUserDetails(lstEmployeedetails, value, TPLockvalue, underuser, SPLASHID, EdetailingId, DACode, strGuid, daCode);
                    if (result.Split(':')[0] == "SUCCESS")
                    {
                        string userCode = result.Split('-')[1];
                        string userName = result.Split('-')[0];
                        //Inset Project Details
                        if (!string.IsNullOrEmpty(projectCode))
                        {
                            int rowsAffected = _objDALUsercretion.InsertUserProjectDetails(companyCode, userCode, projectCode, effectiveFromdate);
                            if (rowsAffected < InsertUserProjectCount)
                            {
                                result = revertInsertedUserDetails(companyCode, employeeCode, userCode, 0, 0, 0, employeeEntrymode, divisionCode, InsertDivisionCount, InsertUserProjectCount);
                            }
                        }

                        if (lstLeavedetails.Count > 0)
                        {
                            lstLeavedetails.ForEach
                            (
                                z => z.User_Code = userCode
                            );
                            int rowsaffected = _objDALUsercretion.InsertLeaveDetails(lstLeavedetails);

                            if (rowsaffected < lstLeavedetails.Count)
                            {
                                result = revertInsertedUserDetails(companyCode, employeeCode, userCode, 0, 0, lstLeavedetails.Count, employeeEntrymode, divisionCode, InsertDivisionCount, InsertUserProjectCount);
                            }
                        }
                        if (lstProductdetails.Count > 0)
                        {
                            lstProductdetails.ForEach
                            (
                                z => z.User_Code = userCode
                            );
                            DataTable dtUserProduct = null;
                            if (lstProductdetails.Count >= 1)
                            {
                                dtUserProduct = new DataTable();
                                dtUserProduct.Columns.Add("Company_Code", typeof(string));
                                dtUserProduct.Columns.Add("User_Code", typeof(string));
                                dtUserProduct.Columns.Add("Product_Code", typeof(string));
                                dtUserProduct.Columns.Add("Current_Stock", typeof(string));
                                dtUserProduct.Columns.Add("Effective_From", typeof(string));
                                dtUserProduct.Columns.Add("Min_Count", typeof(int));
                                dtUserProduct.Columns.Add("Max_Count", typeof(int));

                                for (int i = 0; i < lstProductdetails.Count; i++)
                                {
                                    dtUserProduct.Rows.Add(lstProductdetails[i].Company_Code, lstProductdetails[i].User_Code, lstProductdetails[i].Product_Code, lstProductdetails[i].Current_Stock, lstProductdetails[i].Effective_From, lstProductdetails[i].Min_Count, lstProductdetails[i].Max_Count);
                                }
                            }
                            int insertproduct = _objDALUsercretion.InsertProductDetails(dtUserProduct);

                            if (insertproduct < lstProductdetails.Count)
                            {
                                result = revertInsertedUserDetails(companyCode, employeeCode, userCode, 0, lstProductdetails.Count, lstLeavedetails.Count, employeeEntrymode, divisionCode, InsertDivisionCount, InsertUserProjectCount);
                            }
                        }

                        if (lstNoticeboarddetails.Count > 0)
                        {
                            lstNoticeboarddetails.ForEach
                            (
                                z => z.User_Code = userCode
                            );

                            int insertnotice = _objDALUsercretion.InsertNoticeBoardDetails(lstNoticeboarddetails);

                            if (insertnotice < lstNoticeboarddetails.Count)
                            {
                                result = revertInsertedUserDetails(companyCode, employeeCode, userCode, lstNoticeboarddetails.Count, lstProductdetails.Count, lstLeavedetails.Count, employeeEntrymode, divisionCode, InsertDivisionCount, InsertUserProjectCount);
                            }
                        }
                        //if (lstsplashdetails.Count > 0)
                        //{
                        //    //lstsplashdetails.ForEach
                        //    //            (
                        //    //           // z => z.User_Code = userCode
                        //    //            );

                        //    int insertsplash = _objDALUsercretion.Insertsplash(lstsplashdetails);

                        //    if (insertsplash < lstsplashdetails.Count)
                        //        result = revertInsertedUserDetails(companyCode, employeeCode, userCode, lstsplashdetails.Count, lstProductdetails.Count, lstLeavedetails.Count, employeeEntrymode, divisionCode, InsertDivisionCount, InsertUserProjectCount);
                        //}
                    }
                    else
                    {
                        result = revertInsertedUserDetails(companyCode, employeeCode, "", 0, 0, 0, employeeEntrymode, divisionCode, InsertDivisionCount, InsertUserProjectCount);
                    }
                    //end of user creation
                }
            }
            else
            {
                result = "FAILURE";
            }
            return(result);
        }