Beispiel #1
0
        public HttpResponseMessage CreateBDMAppointmentDetail(BDMAppointmentDetailInsertDTO objAppointmentDetail)
        {
            HttpResponseMessage message;

            try
            {
                // // BDMAppointmentDetailDAL dal = new BDMAppointmentDetailDAL();
                var dynObj = new { result = _obj.InsertBDMAppointmentDetail(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", "CreateBDMAppointmentDetail");
            }
            return(message);
        }
        public bool InsertBDMAppointmentDetail(BDMAppointmentDetailInsertDTO objAppointmentDetail)
        {
            bool res = false;
            BDMAppointmentGetIdDTO bdm    = new BDMAppointmentGetIdDTO();
            SqlCommand             SqlCmd = new SqlCommand("spInsertBDMAppoinmentDetail");

            SqlCmd.CommandType = CommandType.StoredProcedure;
            SqlCmd.Parameters.AddWithValue("@EmployeeId", objAppointmentDetail.EmployeeId);
            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("@ReferBy", (objAppointmentDetail.ReferBy == null) ? "" : objAppointmentDetail.ReferBy);
            SqlCmd.Parameters.AddWithValue("@State", objAppointmentDetail.State);
            SqlCmd.Parameters.AddWithValue("@City", objAppointmentDetail.City);
            SqlCmd.Parameters.AddWithValue("@ExistCompetitors", objAppointmentDetail.ExistCompetitors);
            SqlCmd.Parameters.AddWithValue("@CreatedBy", objAppointmentDetail.CreatedBy);
            bdm = _unitOfWork.DbLayer.GetEntityList <BDMAppointmentGetIdDTO>(SqlCmd).FirstOrDefault();
            if (bdm != null)
            {
                SqlCommand sqlCmd1 = new SqlCommand("spInsertRequirementDetails");
                sqlCmd1.CommandType = CommandType.StoredProcedure;
                sqlCmd1.Parameters.AddWithValue("@ClientId", bdm.ClientId);
                sqlCmd1.Parameters.AddWithValue("@CreatedBy", objAppointmentDetail.CreatedBy);
                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;
                    }
                }
                if (objAppointmentDetail.ExistCompetitors)
                {
                    SqlCommand sqlCmd2 = new SqlCommand("spInsertCompetitors");
                    sqlCmd2.CommandType = CommandType.StoredProcedure;
                    sqlCmd2.Parameters.AddWithValue("@ClientId", bdm.ClientId);
                    sqlCmd2.Parameters.AddWithValue("@CreatedBy", objAppointmentDetail.CreatedBy);
                    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);
        }