示例#1
0
        public HttpResponseMessage UpdateBDMAppointmentDetail(BDMAppointmentDetailUpdateDTO objAppointmentDetail)
        {
            HttpResponseMessage message;

            try
            {
                // BDMAppointmentDetailDAL dal = new BDMAppointmentDetailDAL();
                var dynObj = new { result = _obj.UpdateBDMAppointmentDetail(objAppointmentDetail) };
                message = Request.CreateResponse(HttpStatusCode.OK, dynObj);
            }
            catch (Exception ex)
            {
                message = Request.CreateResponse(HttpStatusCode.BadRequest, new { msgText = "Something wrong. Try Again!" });

                ErrorLog.CreateErrorMessage(ex, "BDMAppoinmentDetail", "UpdateBDMAppointmentDetail");
            }
            return(message);
        }
        public bool UpdateBDMAppointmentDetail(BDMAppointmentDetailUpdateDTO objAppointmentDetail)
        {
            bool       res    = false;
            SqlCommand SqlCmd = new SqlCommand("spUpdateBDMAppoinmentDetail");

            SqlCmd.CommandType = CommandType.StoredProcedure;
            SqlCmd.Parameters.AddWithValue("@Id", objAppointmentDetail.Id);
            SqlCmd.Parameters.AddWithValue("@ClientName", objAppointmentDetail.ClientName);
            SqlCmd.Parameters.AddWithValue("@ClientAddress", objAppointmentDetail.ClientAddress);
            SqlCmd.Parameters.AddWithValue("@ClientContactNo", objAppointmentDetail.ClientContactNo);
            SqlCmd.Parameters.AddWithValue("@ContactPerson", objAppointmentDetail.ContactPerson);
            SqlCmd.Parameters.AddWithValue("@Designation", objAppointmentDetail.Designation);
            SqlCmd.Parameters.AddWithValue("@Mobile", objAppointmentDetail.Mobile);
            SqlCmd.Parameters.AddWithValue("@Email", objAppointmentDetail.Email);
            SqlCmd.Parameters.AddWithValue("@State", objAppointmentDetail.State);
            SqlCmd.Parameters.AddWithValue("@City", objAppointmentDetail.City);
            SqlCmd.Parameters.AddWithValue("@ReferBy", (objAppointmentDetail.ReferBy == null) ? "" : objAppointmentDetail.ReferBy);
            SqlCmd.Parameters.AddWithValue("@ExistCompetitors", objAppointmentDetail.ExistCompetitors);
            SqlCmd.Parameters.AddWithValue("@ModifiedBy", objAppointmentDetail.ModifiedBy);
            int bdm = _unitOfWork.DbLayer.ExecuteNonQuery(SqlCmd);

            SqlCommand SqlCmdDelReq = new SqlCommand("spDeleteRequirementDetails");

            SqlCmdDelReq.CommandType = CommandType.StoredProcedure;
            SqlCmdDelReq.Parameters.AddWithValue("@ClientId", objAppointmentDetail.Id);
            SqlCmdDelReq.Parameters.AddWithValue("@ActionBy", objAppointmentDetail.ModifiedBy);
            int resultReq = _unitOfWork.DbLayer.ExecuteNonQuery(SqlCmdDelReq);

            if (bdm != Int32.MaxValue && resultReq != Int32.MaxValue)
            {
                SqlCommand sqlCmd1 = new SqlCommand("spInsertRequirementDetails");
                sqlCmd1.CommandType = CommandType.StoredProcedure;
                sqlCmd1.Parameters.AddWithValue("@ClientId", objAppointmentDetail.Id);
                sqlCmd1.Parameters.AddWithValue("@CreatedBy", objAppointmentDetail.ModifiedBy);
                sqlCmd1.Parameters.Add(new SqlParameter("@Designation", SqlDbType.Int));
                sqlCmd1.Parameters.Add(new SqlParameter("@Service", SqlDbType.Int));
                sqlCmd1.Parameters.Add(new SqlParameter("@RatePerEmployee", SqlDbType.Int));
                sqlCmd1.Parameters.Add(new SqlParameter("@EmployeeCount", SqlDbType.Int));
                foreach (var requirement in objAppointmentDetail.RequirementDetail)
                {
                    if (sqlCmd1.Connection != null)
                    {
                        if (sqlCmd1.Connection.State == ConnectionState.Closed)
                        {
                            sqlCmd1.Connection.Open();
                        }
                    }

                    sqlCmd1.Parameters["@Designation"].Value     = requirement.Designation;
                    sqlCmd1.Parameters["@Service"].Value         = requirement.Service;
                    sqlCmd1.Parameters["@RatePerEmployee"].Value = requirement.RatePerEmployee;
                    sqlCmd1.Parameters["@EmployeeCount"].Value   = requirement.EmployeeCount;
                    int queryRes = _unitOfWork.DbLayer.ExecuteNonQuery(sqlCmd1);
                    if (queryRes != Int32.MaxValue)
                    {
                        res = true;
                    }
                    else
                    {
                        // this part needed error handling code.
                        res = false;
                    }
                }


                SqlCommand SqlCmdDelCom = new SqlCommand("spDeleteCompetitors");
                SqlCmdDelCom.CommandType = CommandType.StoredProcedure;
                SqlCmdDelCom.Parameters.AddWithValue("@ClientId", objAppointmentDetail.Id);
                SqlCmdDelCom.Parameters.AddWithValue("@ActionBy", objAppointmentDetail.ModifiedBy);
                int resultCom = _unitOfWork.DbLayer.ExecuteNonQuery(SqlCmdDelCom);

                if (objAppointmentDetail.ExistCompetitors && resultCom != Int32.MaxValue)
                {
                    SqlCommand sqlCmd2 = new SqlCommand("spInsertCompetitors");
                    sqlCmd2.CommandType = CommandType.StoredProcedure;
                    sqlCmd2.Parameters.AddWithValue("@ClientId", objAppointmentDetail.Id);
                    sqlCmd2.Parameters.AddWithValue("@CreatedBy", objAppointmentDetail.ModifiedBy);
                    sqlCmd2.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar));
                    sqlCmd2.Parameters.Add(new SqlParameter("@Designation", SqlDbType.VarChar));
                    sqlCmd2.Parameters.Add(new SqlParameter("@Service", SqlDbType.VarChar));
                    sqlCmd2.Parameters.Add(new SqlParameter("@RatePerEmployee", SqlDbType.Int));
                    sqlCmd2.Parameters.Add(new SqlParameter("@EmployeeCount", SqlDbType.Int));
                    foreach (var competitor in objAppointmentDetail.Competitor)
                    {
                        if (sqlCmd2.Connection != null)
                        {
                            if (sqlCmd2.Connection.State == ConnectionState.Closed)
                            {
                                sqlCmd2.Connection.Open();
                            }
                        }
                        sqlCmd2.Parameters["@Name"].Value            = competitor.Name;
                        sqlCmd2.Parameters["@Designation"].Value     = competitor.Designation;
                        sqlCmd2.Parameters["@Service"].Value         = competitor.Service;
                        sqlCmd2.Parameters["@RatePerEmployee"].Value = competitor.RatePerEmployee;
                        sqlCmd2.Parameters["@EmployeeCount"].Value   = competitor.EmployeeCount;
                        int queryRes = _unitOfWork.DbLayer.ExecuteNonQuery(sqlCmd2);
                        if (queryRes != Int32.MaxValue)
                        {
                            res = true;
                        }
                        else
                        {
                            // this part needed error handling code.
                            res = false;
                        }
                    }
                }
                res = true;
            }
            return(res);
        }