示例#1
0
        //Added by Saddam/
        public IHttpActionResult insertExecutive(ExecutiveModel Executive)
        {
            string status = "";

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    ExecutiveMaster _Executive = new ExecutiveMaster();
                    _Executive.executiveName = Executive.executiveName;
                    _Executive.executivecode = Executive.executivecode;
                    _Executive.Emailid       = Executive.Emailid;
                    _Executive.DepartmentId  = Executive.DepartmentId;
                    _Executive.Mobile        = Executive.Mobile;
                    _Executive.Phoneno       = Executive.Phoneno;
                    _Executive.DepartmentId  = Executive.DepartmentId;
                    _Executive.Password      = _encryptionService.EncryptText(Executive.Password, _ExecutiveService.KeyValue("encriptionkey"));
                    _Executive.Id            = Executive.Id;
                    _Executive.EnteredBy     = Executive.EnteredBy;
                    //  status = _ExecutiveService.DuplicityCheck(_Executive);
                    status = _ExecutiveService.DuplicityExecutiveCodeCheck(_Executive);

                    if (status == "Y")
                    {
                        if (Executive.Id == 0)
                        {
                            int ExecutiveIdId = _ExecutiveService.InsertExecutive(_Executive);
                            if (ExecutiveIdId != 0)
                            {
                                ExecutiveDivisionLink Link = new ExecutiveDivisionLink();
                                foreach (var item in Executive.Division)
                                {
                                    Link.executiveid = ExecutiveIdId;
                                    Link.divisionid  = item;
                                    Link.EnteredBy   = Executive.EnteredBy;
                                    _ExecutiveService.InsertExecutiveDivisionLinking(Link);
                                }
                            }

                            if (Executive.ReportingId != 0 && ExecutiveIdId != 0 && Executive.RoleName == "executive")
                            {
                                ExecutiveReporting Reporting = new ExecutiveReporting();
                                Reporting.executiveid   = ExecutiveIdId;
                                Reporting.reportingidto = Executive.ReportingId;
                                Reporting.EnteredBy     = Executive.EnteredBy;
                                _ExecutiveService.InsertExecutiveReporting(Reporting);
                            }
                        }

                        else
                        {
                            ExecutiveMaster mobj_Excutive = _ExecutiveService.GetExecutiveById(_Executive.Id); //_ExecutiveService.GetDivisionById(Executive);
                            mobj_Excutive.executiveName = Executive.executiveName;
                            mobj_Excutive.executivecode = Executive.executivecode;
                            mobj_Excutive.Emailid       = Executive.Emailid;
                            mobj_Excutive.Password      = _encryptionService.EncryptText(Executive.Password, _ExecutiveService.KeyValue("encriptionkey"));
                            mobj_Excutive.Mobile        = Executive.Mobile;
                            mobj_Excutive.Phoneno       = Executive.Phoneno;
                            mobj_Excutive.DepartmentId  = Executive.DepartmentId;
                            mobj_Excutive.ModifiedBy    = Executive.EnteredBy;
                            mobj_Excutive.ModifiedDate  = System.DateTime.Now;

                            _ExecutiveService.UpdateExecutive(mobj_Excutive);

                            ExecutiveDivisionLink Link = new ExecutiveDivisionLink();
                            _ExecutiveService.DeactivateExecutiveDivisionLinking(Executive.Id, Executive.EnteredBy);

                            foreach (var item in Executive.Division)
                            {
                                Link.executiveid = Executive.Id;
                                Link.divisionid  = item;
                                Link.EnteredBy   = Executive.EnteredBy;
                                _ExecutiveService.InsertExecutiveDivisionLinking(Link);
                            }

                            if (Executive.ReportingId != 0)
                            {
                                _ExecutiveService.DeavtivateExecutiveReporting(Executive.Id, Executive.EnteredBy);
                                ExecutiveReporting Reporting = new ExecutiveReporting();
                                Reporting.executiveid = Executive.Id;
                                if (Executive.RoleName == "executive")
                                {
                                    Reporting.reportingidto = Executive.ReportingId;
                                    Reporting.EnteredBy     = Executive.EnteredBy;
                                    _ExecutiveService.InsertExecutiveReporting(Reporting);
                                }
                                else
                                {
                                    Reporting.EnteredBy = Executive.EnteredBy;
                                    _ExecutiveService.UpdateExecutiveReporting(Reporting);
                                }
                            }
                        }


                        //--set executive repoting to or not
                        if (Executive.ReportingId != 0)
                        {
                            ExecutiveMaster mobj_Excutive = _ExecutiveService.GetExecutiveById(Executive.ReportingId);
                            mobj_Excutive.ProcessTransferTo = Executive.ProcessTransferTo;
                            _ExecutiveService.UpdateExecutive(mobj_Excutive);
                        }
                        //-------------------------

                        status = _localizationService.GetResource("Master.API.Success.Message");
                        scope.Complete();
                    }
                    else
                    {
                        status = "Duplicate";
                    }
                }
                catch (ACSException ex)
                {
                    status = ex.InnerException.Message;
                }
                catch (Exception ex)
                {
                    status = ex.InnerException.Message;
                }
            }
            return(Json(status));
        }